in reply to hi i want to retrieve the element and values from xml document
That's a rather open-ended question. But here's a quick demonstration of some of XML::LibXML's capabilities...
use v5.14; use syntax qw( junction ); use XML::LibXML 2 ':all'; my $xml = XML::LibXML->load_xml( IO => \*DATA ); my ($foo) = $xml->getElementsByTagName('foo'); say $foo; # says '<foo>Hello World</foo>' say $foo->textContent; # says 'Hello World' my ($bar) = $xml->findnodes('//bar'); # xpath say $bar; # says '<bar quux="1"/>' say $bar->{quux}; # says '1' my @baz = $xml->findnodes('//baz'); say $_->{xyzzy} for @baz; # says 'a' then 'b' then 'c' my ($comment) = grep { $_->nodeType eq none(XML_ELEMENT_NODE, XML_TEXT_NODE) } $xml->documentElement->childNodes; say $comment; __DATA__ <document> <foo>Hello World</foo> <bar quux="1" /> <baz xyzzy="a" /> <baz xyzzy="b" /> <baz xyzzy="c" /> <!-- yes, this is part of the DOM --> </document>
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: hi i want to retrieve the element and values from xml document
by joyeux (Initiate) on Nov 20, 2012 at 13:16 UTC |
In Section
Seekers of Perl Wisdom