xmlstarlet select value

不羁岁月 提交于 2019-11-30 00:25:39
npostavs

The key is to start from the ITEM node, not the identifyer:

$ xmlstarlet sel -t -c "/DATA/TABLES/ITEM[identifyer/@V=1234]" test.xml
<ITEM>
  <identifyer V="1234"/>
  <property1 V="abcde"/>
  <Property2 V="qwerty"/>
</ITEM>

Then you can pick out the bits you want:

$ xmlstarlet sel -t -c "/DATA/TABLES/ITEM[identifyer/@V=1234]/*" test.xml
<identifyer V="1234"/><property1 V="abcde"/><Property2 V="qwerty"/>

$ xmlstarlet sel -t -v "/DATA/TABLES/ITEM[identifyer/@V=1234]/Property2/@V" test.xml
qwerty
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!