这是 xml 数据:
<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>
我试图找到有价值property2
的项目。我可以选择数据:identifyer
1234
$ xmlstarlet sel -t -c "/DATA/TABLES/ITEM/identifyer [@V=1234]" test.xml
<identifyer V="1234"/>
需要两种类型的输出:
$ xmlstarlet <some magic>
<identifyer V="1234"></identifyer>
<property1 V="abcde"></property1>
<Property2 V="qwerty"></property2>
和:
$ xmlstarlet <some magic>
qwerty