获取xmllint以输出xpath结果\ n分隔,用于属性选择器 [英] Get xmllint to output xpath results \n-separated, for attribute selector
本文介绍了获取xmllint以输出xpath结果\ n分隔,用于属性选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取xmllint为属性每行"输出xpath选择器的多个结果?
How can I get xmllint to output multiple results of xpath selector for attributes "per line"?
以这个例子为例:
<?xml version="1.0" encoding="ISO-8859-1"?>
<config>
<tagX key1="value1 " key2=" value2"/>
<tagY key3="value3" key4=" value4 "/>
</config>
$ xmllint example.xml --xpath "/config/*/@*"
结果是:
key1="value1 " key2=" value2" key3="value3" key4=" value4 "
我想要得到的是:
key1="value1 "
key2=" value2"
key3="value3"
key4=" value4 "
我是否需要在偶数引号后进行拆分,或者有没有更整洁的方法呢?
Would I need to split after even-numbered quote marks, or is there any neater way to do this?
还有一个相关问题,关于同一主题只是关于挑选<tag>value</tag>
而不是<tag attribute="value" />
There's a related question, about the same subject except it's about picking out contents of <tag>value</tag>
, and not <tag attribute="value" />
推荐答案
您可以尝试:
$ xmllint --shell inputfile <<< `echo 'cat /config/*/@*'`
不过,您可能需要grep
输出,以便过滤掉不需要的行.
You might need to grep
the output, though, so as to filter the undesired lines.
这篇关于获取xmllint以输出xpath结果\ n分隔,用于属性选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文