$ 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>
- 格式化xml文件
$ xmllint t.xml
- 提取element文本
$ xmllint --xpath '//resources/item[@id="item1"]/value/text()' t.xml
VALUE1
- 提取element屬性
$ xmllint--xpath 'string(//resources/item[@id="item1"]/@type)' t.xml
type1
- 提取多個element屬性
$ xmllint --xpath 'concat(//resources/item[@id="item1"]/@type, "-", //resources/item[@id="item2"]/@type)' t.xml
type1-type2
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者