0
votes

I have an xml file as shown below. I want to use xmllint to parse it such that if the category is "SciFi", it will display the "isbn" number.

After struggling a bit I could figure out how to print only the category or only the isbn number ; but cannot figure out how to add the condition.

<book>
 <name>
  <category>SciFi</category>
  <isbn>12345678</isbn>
 </name>
 <name>
  <category>Mystery</category>
  <isbn>23456789</isbn>
 </name>
<book>

Edit : The version of xmllint I have does not support xpath

I made a mistake in my original post ; corrected xml above

xmllint --version produces

xmllint: using libxml version 20626

I use the following commands to print the information

cat /book/name[1]/category
cat /book/name[2]/category

cat /book/name[1]/isbn
cat /book/name[2]/isbn
1
Why not switch to a newer version (or even another program) that does support xpath? - BeniBela
And how do I justify that to the support team to get it installed on some 1000+ Linux servers ? - souser
What version of xmllint are you using and how are you printing only the category or isbn? - Daniel Haley
I have updated my post accordingly. - souser

1 Answers

0
votes

This sounds like a poor tool for the purpose. If you have xmllint installed, do you have xsltproc? That would be more useful, I think.

Also, just to be sure, have you tried cat /book/name[category='SciFi']/isbn ?