Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

How do i get value of an element if the next elememnt has specific value in XML::LibXML using Xpath?

by ravi06 (Novice)
on Jul 07, 2013 at 19:09 UTC ( #1043000=perlquestion: print w/replies, xml ) Need Help??
ravi06 has asked for the wisdom of the Perl Monks concerning the following question:

<book:bookResource> <book:book> <book:meta coverImage="/cover.gif" doi="10.1088" publicationDate="2016 +-12-01" issn="1111-222X" collectionId="0001"> <book:title title="Lattice dynamics"> <book:subTitle>Book 17</book:subTitle></book:title> <book:isbn isbn="979-0-4444-1000-17" type="epub"/> <book:isbn isbn="979-0-4444-2000-2" type="ppub"/> </book:meta> </book:bookResource> </book:book>

How can I get isbn="979-0-4444-1000-17" for type="epub"? I tried the following code, but of no use. Help me please.

use XML::LibXML; my $parser = XML::LibXML->new(); my $doc = $parser->parse_file("book_service.xml"); my $xpc = XML::LibXML::XPathContext->new($doc->documentElement()); foreach my $book_node ($xpc->findnodes('/book:bookResource/book:book/b +ook:meta')) { foreach $book_element ('./*/@isbn[@type="epub"]') { print $book_node->findvalue($book_element); } }

  • Comment on How do i get value of an element if the next elememnt has specific value in XML::LibXML using Xpath?
  • Select or Download Code

Replies are listed 'Best First'.
Re: How do i get value of an element if the next elememnt has specific value in XML::LibXML using Xpath? (OT)
by LanX (Chancellor) on Jul 07, 2013 at 19:20 UTC
    Sorry, isn't this rather an XPath than a Perl-question?

    edit
    From my memory and w/o ever working with this module

    you should try experimenting with something like

    ./book:isbn[@type="epub"]/@isbn

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re: How do i get value of an element if the next elememnt has specific value in XML::LibXML using Xpath?
by Anonymous Monk on Jul 08, 2013 at 01:23 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1043000]
help
Chatterbox?
[stevieb]: Marshall: no. I commented on the thread yesterday. Visual Studio updates the tags ok, but corrupts the exe
[stevieb]: I advised the OP that a possible workaround would be to add a version function/flag that displays the required copyright/license info instead
[Marshall]: Darn! I'll look at the thread. Must not be updatinga byte count somewhere. The .exe format is a complex critter.
[stevieb]: that way, it's still "hard coded" into the exe at least, despite not being visible via Properties
[Marshall]: I also looked into PerlApp from Active State, but they don't sell their Dev Kit independent of a very expensive ($1,200) per year license anymore.
[Corion]: I would assume that the PE format hasn't changed that much since the days of yore, but it seems that I would be wrong in that assumption
[Marshall]: When I bought my copy 15+ years ago, it was just a couple hundred bucks.
[Marshall]: I looked at MS specs for PE format and I didn't see any changes in last decade, but evidenly that would be wrong.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2016-12-08 18:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (144 votes). Check out past polls.