Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

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

The xml is as below:

<book:bookResource xmlns:book="http://api.iop.org/Book/1.0/"> <book:book> <book:meta doi="10.1088/bk111111" publisherId="bk111111" publisher="Pu +blishing" platform="science"> </book:meta> <book:locator xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/ +book/isbn/979-0- 4444-1000-17?releaseStatus=RELEASED" xlink:title="979-0-4444-1000-17" xlink:type="locator"> </book:locator> <book:contents> <book:chapter id="bk444444ch1" type="CHAPTER"> <book:locator xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/ +book/isbn/979-0- 4444-1000-17/book-part/chapter/bk444444ch1?releaseStatus=RELEASED" xlink:role="http://www.iop.org/roles/book-part-locator" xlink:title="P +hotonic crystal light-emitting sources" xlink:type="locator"></book:locator> <book:locator xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/ +book/isbn/979-0- 4444-1000-17/book-part/chapter/bk444444ch1?releaseStatus=RELEASED&amp; +format=pdf" xlink:role="http://www.iop.org/roles/book-part-pdf-locator" xlink:titl +e="Photonic crystal light-emitting sources" xlink:type="locator"></book:locator> <book:locator xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/ +book/isbn/979-0- 4444-1000-17/book-part/chapter/bk444444ch1?releaseStatus=RELEASED&amp; +format=epub" xlink:role="http://www.iop.org/roles/book-part-epub-locator" xlink:tit +le="Photonic crystal light-emitting sources" xlink:type="locator"></book:locator> <book:meta doi="10.1088/bk444444ch1" firstPage="1-1" lastPage="1-118"> + <book:author givenName="J E" surname="Field"> <book:affiliation xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="bk444444ch1af1" xlink:role="http://www.iop.org/roles/affiliation-locator" xlink:type=" +locator"> </book:affiliation> </book:author> <book:affiliation name="Cavendish Laboratory, University of Cambridge" +> <book:locator xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="b +k444444ch1af1" xlink:role="http://www.iop.org/roles/affiliation-locator" xlink:type=" +locator"> </book:locator> </book:affiliation> </book:meta> </book:chapter> </book:contents> </book:book> </book:bookResource>

The complete code is :

my %book_columns = ( 'Book_Id' => '@publisherId', 'Book_Platform' => '@platform', 'Book_Publisher' => '@publisher', ); my %chapter_columns = ( 'Chapter_Doi' => 'book:meta/@doi', 'Chapter_Doi_Prefix' => 'substring-before(book +:meta/@doi,"/")', 'Chapter_Id' => '@id', 'Chapter_Title' => 'book:locator[contains(@xli +nk:href, "format=epub")]/@xlink:title', );
my $dom = $parser->parse_string(book.xml); my $root = $dom->documentElement(); my $xpc = XML::LibXML::XPathContext->new($root); $xpc->registerNs('book', 'http://api.iop.org/Book/1.0/'); $xpc->registerNs('xlink', 'http://www.w3.org/1999/xlink'); foreach my $chapter_node ($xpc->findnodes('/book:bookResource/book:boo +k/book:meta | /book:bookResource/book:book/book:contents/book:chapter +')) { foreach my $col(qw/Chapter_Id Chapter_Title Book_Id Book_Publisher + Book_Platform Chapter_Doi_Prefix Chapter_Doi Chapter_Id/) { print $xpc->findvalue($chapter_columns{$col}, $chapter_node); } }

In reply to Re^4: How can I force findnodes() to check value of attributes in either xpath1 or xpath2? by ravi06
in thread How can I force findnodes() to check value of attributes in either xpath1 or xpath2? 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 having an uproarious good time at the Monastery: (3)
As of 2024-04-24 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found