I've tried to use xmlstarlet
and am having difficulty. I have the following XML feed.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RESPONSE VERSION="L100" REQUEST="show volume-statistics">
<OBJECT basetype="volume-statistics" name="volume-statistics" oid="1" format="rows">
<PROPERTY name="volume-name" display-name="Name">VOL0</PROPERTY>
<PROPERTY name="volume-IOPS" display-name="IOPS">100</PROPERTY>
</OBJECT>
</RESPONSE>
I need to select the IOPS value where the name is equal to VOL0
and print only the value of the volume-IOPS.
I have tried following Commands:
xmlstarlet sel -t -m "RESPONSE/OBJECT/PROPERTY/[@display-name='VOL0']" -v "RESPONSE/OBJECT/PROPERTY[@volume0IOPS] test.xml
Example Output
100
You can do this with a single XPath expression, that retrieves the <OBJECT/>
element which contains the "VOL0" name property, and then selects the respective IOPS property.
xmlstarlet sel -t -v '
/RESPONSE/OBJECT[PROPERTY[@name="volume-name"]="VOL0"]
/PROPERTY[@name="volume-IOPS"]' test.xml