Linux常用工具之 - xmllint

2024-10-09  本文已影响0人  CodingCode
$ 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
上一篇 下一篇

猜你喜欢

热点阅读