XMLLINT 获取第一个匹配的子元素

问题描述 投票:0回答:1

给定 xml

<parent>
   <child> test1 </child>
   <child> test2 </child>
</parent>

使用 xmllint 我可以得到孩子:

| xmllint --format --xpath '//parent/child/text()' -   

这将返回所有子文本

 test1 test2

但是我只想获取第一个/或第二个子内容。 如何选择合适的孩子位置?

xmllint
1个回答
0
投票

指定位置为

//parent/child[1]/text()
//parent/child[2]/text()
© www.soinside.com 2019 - 2024. All rights reserved.