xmlstarlet Search Attribute

2019-07-23 16:20发布

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条回答
The star\"
2楼-- · 2019-07-23 17:00

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.

查看更多
登录 后发表回答