xmlstarlet Search Attribute

陌路散爱 提交于 2019-12-24 10:41:11

问题


XML Example:

<?xml version="1.0" encoding="UTF-8"?>
<profile>
<section name="Vision">
<key name="Name" value="BBBB"/>
<key name="Name_Remark" value="GGGG"/>
<key name="Position" value="30"/>
</section>
</profile>

How I can get value with xmlstarlet where name is "Position". Now is 30.

Thank you.


回答1:


You can use this command line...

xmlstarlet sel -t -v "/profile/section/key[@name='Position']/@value" -n input.xml

The sel command tells xmlstarlet to select.

The -t option tells xmlstarlet the options following -t are for templates.

The -v tells xmlstarlet to print the value of the XPath expression.

The -n tells xmlstarlet to print a new line. (Not completely necessary.)

All of this can be found by running xmlstarlet sel --help from the command line.



来源:https://stackoverflow.com/questions/44209350/xmlstarlet-search-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!