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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.