Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

XML::Simple folds (by default) on the name= attribute. At lines -3, -8 from the end you have two <members> lines with the same name="AttributeDesc". This fooled XML::Simple into treating the two blocks as the same, allowing the second instance to overwrite the first. By adding KeyAttr=>[] as an option to XMLin, this default behaviour is suppressed and the expected result is obtained.

use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); use XML::Simple; my $x = XMLin(<<'END', KeyAttr=>[]); <classes name="Panoply::AttributeDesc"> <all_members name="AttributeDesc" protection="public" scope="Panop +ly::AttributeDesc" virtualness="non_virtual"/> <all_members name="AttributeDesc" protection="public" scope="Panop +ly::AttributeDesc" virtualness="non_virtual"/> <all_members name="description" protection="public" scope="Panoply +::AttributeDesc" virtualness="non_virtual"/> <all_members name="name" protection="public" scope="Panoply::Attri +buteDesc" virtualness="non_virtual"/> <all_members name="value" protection="private" scope="Panoply::Att +ributeDesc" virtualness="non_virtual"/> <public_members> <members kind="variable" name="name" protection="public" static= +"no" type="std::string" virtualness="non_virtual"></members> <members kind="variable" name="value" protection="public" static +="no" type="std::string" virtualness="non_virtual"></members> <members kind="variable" name="description" protection="public" +static="no" type="std::string" virtualness="non_virtual"></members> </public_members> <public_methods> <members const="no" kind="function" name="AttributeDesc" protect +ion="public" static="no" virtualness="non_virtual" volatile="no"> <parameters declaration_name="name" type="const std::string &a +mp;"/> <parameters declaration_name="value" type="const std::string & +amp;"/> <parameters declaration_name="desc" default_value="&quot;&quot +;" type="const std::string &amp;"/> </members> <members const="no" kind="function" name="AttributeDesc" protect +ion="public" static="no" virtualness="non_virtual" volatile="no"></me +mbers> </public_methods> </classes> END #pp($x); sub r($$$;$); sub r($$$;$) {my ($r, $l, $e, $a) = @_; $a = [] unless $a; return unless $l and ref($l); if (ref($l) =~ /HASH/) {for(sort keys %$l) {unless (/$e/) {push @$a, $_; r($r, $l->{$_}, $e, $a); pop @$a; } else {&$r(@$a); } } } elsif (ref($l) =~ /ARRAY/) {for(1..@$l) {unless ($l->[$_-1] =~ /$e/) {push @$a, $_; r($r, $l->[$_-1], $e, $a); pop @$a; } else {&$r(@$a); } } } } r sub {say "@_"}, $x, "parameters";

Produces

public_methods members 1

In reply to Re^3: getting ancestors of element by philiprbrenan
in thread getting ancestors of element by jccunning

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2024-04-23 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found