This is the xml-data:
<DATA VERSION="1.0">
<TABLES>
<ITEM>
<identifyer V="1234"></identifyer>
<property1 V="abcde"></property1>
<Property2 V="qwerty"></property2>
</ITEM>
<ITEM>
<identifyer V="5678"></identifyer>
<Property1 V="zyxwv"></property1>
<Property2 V="dvorak"></property2>
</ITEM>
</TABLES>
</DATA>
I am trying to find property2
of the item where identifyer
has value 1234
. I can select the data:
$ xmlstarlet sel -t -c "/DATA/TABLES/ITEM/identifyer [@V=1234]" test.xml
<identifyer V="1234"/>
Two types of output would be desirable:
$ xmlstarlet <some magic>
<identifyer V="1234"></identifyer>
<property1 V="abcde"></property1>
<Property2 V="qwerty"></property2>
And:
$ xmlstarlet <some magic>
qwerty
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…