XPath to display available tags non-recursively (using xmllint in a shell script)
I am trying to construct an XPath argument for use in an xmllint program (used in a Bash shell script) that will return a list of available tags in a tag (while not listing subtags).
Here is the kind of XML I have:
<functionInformation>
<class>
setup
</class>
<description>
This is a natural language description of this function.
</description>
<prerequisiteFunctions>
myFunction1
myFunction2
</prerequisiteFunctions>
<prerequisitePrograms>
myProgram1
myProgram2
</prerequisitePrograms>
</functionInformation>
This XML is stored in the Bash variableInformation.
The result I would like to use when using xmllint in this XML is the following:
class
description
prerequisiteFunctions
prerequisitePrograms
I should note that I would like the tags to return in a non-recursive way (I don't want all the available tags or subtitles to be listed).
I can access the information in tags using xmllint in this way:
descriptionFunctionInformation="$(echo "${functionInformation}"\
| xmllint --xpath '/functionInformation/description/text()' -\
| xargs -i echo -n "{}")"
Could you please point me in the right direction, how can I build XPath (or something similar) to return the information I need?
+3
source to share