Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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 ( [id://1043022]=note: print w/replies, xml ) Need Help??


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

Attributes cannot have attributes, they're attributes not elements

xpather.pl can help you

$ perl xpather.pl ravi06.xml /book:bookResource/book:book/book:meta/book:title/book:subTitle # posy /book:bookResource[1]/book:book[1]/book:meta[1]/book:title[1]/book:sub +Title[1] # star /*[ name() = "book:bookResource" and position() = 1 ] /*[ name() = "book:book" and position() = 1 ] /*[ name() = "book:meta" and position() = 1 and @coverImage = "/cover. +gif" and @doi = "10.1088" and @publicationDate = " 2016-12-01" and @issn = "1111-222X" and @collectionId = "0001" ] /*[ name() = "book:title" and position() = 1 and @title = "Lattice dyn +amics" ] /*[ name() = "book:subTitle" and position() = 1 ] # rats /book:bookResource[1] /book:book[1] /*[ name() = "book:meta" and position() = 1 and @coverImage = "/cover +.gif" and @doi = "10.1088" and @publicationDate = "2016-12-01" and @issn = "1111-222X" and @collectionId = "0001" ] /*[ name() = "book:title" and position() = 1 and @title = "Lattice dy +namics" ] /book:subTitle[1] # "content" Book 17 ------ /book:bookResource/book:book/book:meta/book:isbn[1] # posy /book:bookResource[1]/book:book[1]/book:meta[1]/book:isbn[1] # star /*[ name() = "book:bookResource" and position() = 1 ] /*[ name() = "book:book" and position() = 1 ] /*[ name() = "book:meta" and position() = 1 and @coverImage = "/cover. +gif" and @doi = "10.1088" and @publicationDate = " 2016-12-01" and @issn = "1111-222X" and @collectionId = "0001" ] /*[ name() = "book:isbn" and position() = 1 and @isbn = "979-0-4444-10 +00-17" and @type = "epub" ] # rats /book:bookResource[1] /book:book[1] /*[ name() = "book:meta" and position() = 1 and @coverImage = "/cover +.gif" and @doi = "10.1088" and @publicationDate = "2016-12-01" and @issn = "1111-222X" and @collectionId = "0001" ] /*[ name() = "book:isbn" and position() = 1 and @isbn = "979-0-4444-1 +000-17" and @type = "epub" ] # "content" ------ /book:bookResource/book:book/book:meta/book:isbn[2] # posy /book:bookResource[1]/book:book[1]/book:meta[1]/book:isbn[2] # star /*[ name() = "book:bookResource" and position() = 1 ] /*[ name() = "book:book" and position() = 1 ] /*[ name() = "book:meta" and position() = 1 and @coverImage = "/cover. +gif" and @doi = "10.1088" and @publicationDate = " 2016-12-01" and @issn = "1111-222X" and @collectionId = "0001" ] /*[ name() = "book:isbn" and position() = 2 and @isbn = "979-0-4444-20 +00-2" and @type = "ppub" ] # rats /book:bookResource[1] /book:book[1] /*[ name() = "book:meta" and position() = 1 and @coverImage = "/cover +.gif" and @doi = "10.1088" and @publicationDate = "2016-12-01" and @issn = "1111-222X" and @collectionId = "0001" ] /*[ name() = "book:isbn" and position() = 2 and @isbn = "979-0-4444-2 +000-2" and @type = "ppub" ] # "content" ------ $ $ $ $ $ perl xpather.pl ravi06.xml //*[@isbn] /book:bookResource/book:book/book:meta/book:isbn[1] # posy /book:bookResource[1]/book:book[1]/book:meta[1]/book:isbn[1] # star /*[ name() = "book:bookResource" and position() = 1 ] /*[ name() = "book:book" and position() = 1 ] /*[ name() = "book:meta" and position() = 1 and @coverImage = "/cover. +gif" and @doi = "10.1088" and @publicationDate = " 2016-12-01" and @issn = "1111-222X" and @collectionId = "0001" ] /*[ name() = "book:isbn" and position() = 1 and @isbn = "979-0-4444-10 +00-17" and @type = "epub" ] # rats /book:bookResource[1] /book:book[1] /*[ name() = "book:meta" and position() = 1 and @coverImage = "/cover +.gif" and @doi = "10.1088" and @publicationDate = "2016-12-01" and @issn = "1111-222X" and @collectionId = "0001" ] /*[ name() = "book:isbn" and position() = 1 and @isbn = "979-0-4444-1 +000-17" and @type = "epub" ] # "content" ------ /book:bookResource/book:book/book:meta/book:isbn[2] # posy /book:bookResource[1]/book:book[1]/book:meta[1]/book:isbn[2] # star /*[ name() = "book:bookResource" and position() = 1 ] /*[ name() = "book:book" and position() = 1 ] /*[ name() = "book:meta" and position() = 1 and @coverImage = "/cover. +gif" and @doi = "10.1088" and @publicationDate = " 2016-12-01" and @issn = "1111-222X" and @collectionId = "0001" ] /*[ name() = "book:isbn" and position() = 2 and @isbn = "979-0-4444-20 +00-2" and @type = "ppub" ] # rats /book:bookResource[1] /book:book[1] /*[ name() = "book:meta" and position() = 1 and @coverImage = "/cover +.gif" and @doi = "10.1088" and @publicationDate = "2016-12-01" and @issn = "1111-222X" and @collectionId = "0001" ] /*[ name() = "book:isbn" and position() = 2 and @isbn = "979-0-4444-2 +000-2" and @type = "ppub" ] # "content" ------ $
//*[ name() = "book:isbn" and @isbn and @type = "ppub" ]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1043022]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-28 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found