美文网首页
Linux常用工具之 - xmllint

Linux常用工具之 - xmllint

作者: CodingCode | 来源:发表于2024-10-09 07:21 被阅读0次
$ cat t.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <item id="item1" type="type1">
        <value>VALUE1</value>
   </item>
   <item id="item2" type="type2">
        <value>VALUE2</value>
   </item>
</resources>
  1. 格式化xml文件
$ xmllint t.xml
  1. 提取element文本
$ xmllint --xpath '//resources/item[@id="item1"]/value/text()' t.xml
VALUE1
  1. 提取element属性
$ xmllint--xpath 'string(//resources/item[@id="item1"]/@type)' t.xml
type1
  1. 提取多个element属性
$ xmllint --xpath 'concat(//resources/item[@id="item1"]/@type, "-", //resources/item[@id="item2"]/@type)' t.xml
type1-type2

相关文章

网友评论

      本文标题:Linux常用工具之 - xmllint

      本文链接:https://www.haomeiwen.com/subject/fufirjtx.html