Tuesday, January 26, 2016

Getting child node names from xmlstarlet

Ok. Just throwing this out there, because I was banging my head on my desk this morning trying to figure this out. I couldn't find any simple examples of this, but that could just be due to my inability to find things. I would have likely fared better if I asked my wife to find it for me. (It certainly works for my car keys). Here's hoping this helps someone.

cat <xml file>|  xmlstarlet sel -t -m "//path/to/child::node()" -v "name()" -n

with XML like this:

<?xml version="1.0" encoding="UTF-8"?><landshark_properties VERSION="2.3.1">
<value>Dev Copies</value>
<description>The ONE group Landshark setup will create for the dSources - No need to change</description>

Output like this:
cat text.xml |  xmlstarlet sel -t -m "//content/child::node()" -v "name()" -n