1 2 3 4 5 6 7 8 9 10 11
my $parser = XML::LibXML->new(); my $tree = $parser->parse_file($xmlfile); my $root = $tree->getDocumentElement; my @nodes=$tree->getElementsByTagName('menu'); foreach(@nodes) { print "node\n"; print $_->GetAttribute('name'); print "\n"; }
QuoteCan't locate object method "GetAttribute" via package "XML::LibXML::Element" at
./makecppui.pl line 51 (#1)
(F) You called a method correctly, and it correctly indicated a package
functioning as a class, but that package doesn't define that particular
method, nor does any of its base classes. See perlobj.
Uncaught exception from user code:
Can't locate object method "GetAttribute" via package "XML::LibXML::Element" at ./makecppui.pl line 51.
at ./makecppui.pl line 51
QuoteWieso ist denn das einen-Holzweg-erzeugend?Can't locate object method "GetAttribute" via package "XML::LibXML::Element"
QuoteYou called a method correctly, and it correctly indicated a package
functioning as a class
2014-11-03T18:50:36 ariserIch hatte ja ursprünglich XML::Simple im Auge, aber da wurde andernorts auch abgeraten.
QuoteSTATUS OF THIS MODULE ^
The use of this module in new code is discouraged. Other modules are available which provide more straightforward and consistent interfaces. In particular, XML::LibXML is highly recommended.
The major problems with this module are the large number of options and the arbitrary ways in which these options interact - often with unexpected results.
Patches with bug fixes and documentation fixes are welcome, but new features are unlikely to be added.
https://metacpan.org/pod/distribution/XML-LibXML/lib/XML/LibXML/Element.pod#getAttributegetAttribute
$avalue = $node->getAttribute( $aname );
If $node has an attribute with the name $aname, the value of this attribute will get returned.