Reputation: 3235
Using xmlstarlet/xpath, how do I get the name of all child elements of a certain node? For example, I want to get all the child element names of /a
<a>
<b><c/></b>
<d/>
</a>
Should return:
b
d
I tried
xmlstarlet sel -t -c 'name(/a/*)' -
but this only gives me b
Upvotes: 1
Views: 1973
Reputation: 167471
I don't think an XPath 1.0 expression can do it, you either need XPath 2.0 /a/*/name()
(which I don't think xmlstarlet supports) or you need to use XSLT or try to use the xmlstarlet command line options to try to mimic XSLT. I don't have access to that tool and I am not familiar with details, according to http://xmlstar.sourceforge.net/doc/xmlstarlet.txt you could try
xmlstarlet sel -t -m "/a/*" -v "name()"
Untested.
Upvotes: 6