xmlstarlet 不适用于基于子字符串值的简单选择

xmlstarlet not working for simple selection based on child string value

我正在处理 XML 文件,如

<bookstore> 
   <book category="cooking"> 
       <title lang="en">Everyday Italian</title> 
       <author>adc</author> 
       <year>2005</year> 
       <price>30.00</price> </book> 
   <book category="children"> 
       <title lang="en">Harry Potter</title> 
       <author>xyz</author> 
       <year>2005</year> 
       <price>29.99</price> </book> 
</bookstore>

在 linux

上使用 xmlstarlet
xmlstarlet sel -t -m 'bookstore/author [1]' -n books.xml 

输出结果为 "adc",但是当我已经知道该值时如何找到该字段?

据我所知,作者标签具有价值 "adc"。 我应该如何找到 bookstore/author [x]x

经过一番搜索,我找到了答案并将其留给其他人偶然发现了同样的问题

到select xmlstarlet 中的字段值使用

xmlstarlet -t -c 'bookstore/book[author="adc"]' -n books.xml

这里bookstore/book是包含作者的节点的完整路径 [author=value] 仅用于 select 作者具有特定值的节点 books.xml 是你的 xml 文件

我相信其他人可以更好地解释,但希望这对您有所帮助