Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

<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); } }


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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found