给定 xml
<parent>
<child> test1 </child>
<child> test2 </child>
</parent>
使用 xmllint 我可以得到孩子:
| xmllint --format --xpath '//parent/child/text()' -
这将返回所有子文本
test1 test2
但是我只想获取第一个/或第二个子内容。 如何选择合适的孩子位置?
指定位置为
//parent/child[1]/text()
//parent/child[2]/text()