xmlstarlet 搜索属性 [英] xmlstarlet Search Attribute

查看:23
本文介绍了xmlstarlet 搜索属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XML 示例:

<?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>

如何使用名称为Position"的 xmlstarlet 获取价值.现在是 30.

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

谢谢.

推荐答案

你可以使用这个命令行...

You can use this command line...

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

sel 命令告诉 xmlstarlet 选择.

The sel command tells xmlstarlet to select.

-t 选项告诉 xmlstarlet -t 后面的选项用于模板.

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

-v 告诉 xmlstarlet 打印 XPath 表达式的值.

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

-n 告诉 xmlstarlet 打印一个新行.(并非完全必要.)

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

所有这些都可以通过从命令行运行 xmlstarlet sel --help 来找到.

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

这篇关于xmlstarlet 搜索属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆