in reply to Re^3: How to parse xml with namespase vale in XMl:LibXML? (xmllint --shell setns / xpathtester)
in thread How to parse xml with namespase value in XMl:LibXML?
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $xml = XML::LibXML->load_xml(IO => *DATA); my $root = $xml->documentElement; my $chapter_node = $root->findnodes('book:chapter')->[0]; print $chapter_node->findvalue('./book:locator/@*') . "\n"; __DATA__ <book xmlns:book='b'> <!-- Namespace definition missing in the origina +l data --> <book:chapter id="bk444444ch1" type="CHAPTER"> <book:locator xlink:href="/book/isbn/979-0-4444-1000-17/book-part/chap +ter/bk444444ch1?releaseStatus=RELEASED" xlink:title="Photonic crystal + light-emitting sources" xlink:type="locator" xmlns:xlink="http://www +.w3.org/1999/xlink"/> <book:locator xlink:href="/book/isbn/979-0-4444-1000-17/book-part/chap +ter/bk444444ch1?releaseStatus=RELEASED&format=pdf" xlink:title="P +hotonic crystal light-emitting sources" xlink:type="locator" xmlns:xl +ink="http://www.w3.org/1999/xlink"/> <book:locator xlink:href="/book/isbn/979-0-4444-1000-17/book-part/chap +ter/bk444444ch1?releaseStatus=RELEASED&format=epub" xlink:title=" +Photonic crystal light-emitting sources" xlink:type="locator" xmlns:x +link="http://www.w3.org/1999/xlink"/> </book:chapter> <!-- Missing in the original data --> </book>
Note the changes I made to your data. Maybe your $chapter_node contains something else?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: How to parse xml with namespase vale in XMl:LibXML? (xmllint --shell setns / xpathtester)
by ravi06 (Novice) on Jul 08, 2013 at 19:11 UTC | |
by choroba (Cardinal) on Jul 08, 2013 at 20:30 UTC | |
by Anonymous Monk on Jul 09, 2013 at 02:42 UTC | |
by Anonymous Monk on Jul 09, 2013 at 04:46 UTC | |
by Anonymous Monk on Jul 09, 2013 at 06:33 UTC | |
by Anonymous Monk on Jul 13, 2013 at 23:11 UTC |