I want to retrieve value of <release-date> element where <title> having value 'Solaris' and not other title elements. ... I tired XPath something like my $title= $xp->find("/playlist/movie[title='Solaris']/release-date", $node); But result is not as expected OutPut ::2002-11-27
If the question is what is the <release-date> of the movie with the <title> "Solaris", isn't the correct answer "2002-11-27"? Both XML::LibXML and XML::XPath seem to work fine for me with the exact XPath expression you've shown. <update> All that the code you showed seems to try to do is build an array of hashes containing the <title> elements' values, which doesn't seem to fit your problem statement. </update>
my $file = '/tmp/1193350.xml'; my $xpath = q{/playlist/movie[title='Solaris']/release-date}; use XML::LibXML; my $doc = XML::LibXML->load_xml(location=>$file); for my $node ( $doc->findnodes($xpath) ) { print "XML::LibXML: ",$node->textContent,"\n"; } use XML::XPath; my $xp = XML::XPath->new(filename=>$file); my $nodeset = $xp->find($xpath); for my $node ($nodeset->get_nodelist) { print " XML::XPath: ",$node->string_value,"\n"; } __END__ XML::LibXML: 2002-11-27 XML::XPath: 2002-11-27
In reply to Re: get specific value of element using xpath in perl
by haukex
in thread get specific value of element using xpath in perl
by snehit.ar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |