So, I have used XPath before to take data from a XML sheet and print it out so that
Property1 – Property2 – Property3
are displayed like that. Now, I want to do the same in Linux Bash. I know how to use Linux Bash a little, and was able to get some of it to print out, but not like I needed it to.
Here is an example of how the XML sheet will look
<xml>
<content>
<items>
<item>
<name>I need this information</name>
<item>
<lists>
<list>
<name>I DONT need this information</name>
</list>
<hello>
<name> I need this information also</name>
<hello>
Notice that I have three instances of name so I cant simply use
cat xmlfile | grep “name”
since there is more than one place that has name
Thanks!
Use XMLStarlet to execute your query as XPath.
Also, some very new versions of
xmllinthave a--xpathargument which can be used to run queries.