Why can't extract data with xidel?

169 views Asked by At

Display content in books.xml.

cat  books.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>   
   <book category="JAVA">
      <title lang="en">Learn Java in 24 Hours</title>
      <author>Robert</author>
      <year>2005</year>
      <price>32.00</price>
   </book>
   <book category="XML">
      <title lang="en">Learn XPath in 24 hours</title>
      <author>Jay Ban</author>
      <year>2010</year>
      <price>16.50</price>
   </book>   
</books>

The xquery string:

xstring='''
for $x in doc("books.xml")/books/book
where $x/price>30
return $x/title'''

Why can't extract the book title whose price is larger than 30 with xidel?

Both where $x/price>30 and where $x/price/text)>30 can't take effect.

enter image description here

2

There are 2 answers

1
Jack Fleeting On BEST ANSWER

Assuming your xml is stored in file.xml, this should work:

xidel file.xml --xquery 'for $x in //book where $x/price/text() gt 30 return $x/title'

My output:

Learn Java in 24 Hours
0
showkey On
xquery='''
for $x in doc("books.xml")/books/book
where $x/price/text() >30
return $x/title'''

The bash command:

xidel books.xml --xquery  "$xquery"