Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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 ( #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" ]


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2015-07-29 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (268 votes), past polls