xpath - XML Path needed -


i have following xml file:

<?xml version="1.0" encoding="utf-8"?> <bookstore> <book category="cooking">   <title lang="en">everyday italian</title>   <author>giada de laurentiis</author>   <year>2005</year>   <price>30.00</price> </book> <book category="children">   <title lang="en">harry potter</title>   <author>j k. rowling</author>   <year>2005</year>   <price>29.99</price> </book> <book category="web">   <title lang="en">xquery kick start</title>   <author>james mcgovern</author>   <author>per bothner</author>   <author>kurt cagle</author>   <author>james linn</author>   <author>vaidyanathan nagarajan</author>   <year>2003</year>   <price>49.99</price>   </book> <book category="web">   <title lang="en">learning xml</title>   <author>erik t. ray</author>   <year>2003</year>   <price>39.95</price>   </book> </bookstore> 

i need write xml path returns book published after 2003, category children , need display author , title of book? frustrating have in xpath wrote except missing author.

use following xpath expression:

/bookstore/book[@category="children" , year>2003]/*[name()="author" or name()="title"] 

here select every book category attribute equaling children , year node value more 2003. *[name()="author" or name()="title"] helps select specific children: author , title.

demo using xmllint tool:

$ xmllint input.xml --xpath '/bookstore/book[@category="children" , year > 2003]/*[name()="author" or name()="title"]' <title lang="en">harry potter</title> <author>j k. rowling</author> 

if want see values of author , title nodes, add /text() end of xpath expression:

$ xmllint input.xml --xpath '/bookstore/book[@category="children" , year > 2003]/*[name()="author" or name()="title"]/text()' harry potter j k. rowling 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -