in reply to Re^3: getting ancestors of element
in thread getting ancestors of element

Can you tell me why the following only returns something if I remove 'name' from the KeyAttr list. Can you provide list of keys to XMLin. Is it also possible to return something like: public_methods => members => AttributeDesc => parameters for 'desc'.
#!/usr/bin/perl use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); use XML::Simple; my @list; my $x = XMLin(<<'END', KeyAttr=>['name', 'declaration_name']); <classes> <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 {push (@list, join(" => ", @_))}, $x, "desc"; # ret_ancestors sub {say "@_"}, $x, "desc"; my $elist = join("\n", @list); print "$elist\n";