鉴于这个大型深层嵌套 XML 文档 (bookstore.xml) 的片段,我想知道 amazon
节点的完整路径。如何从命令行打印该路径?
<bookstore>
<book>
<title lang="eng">Learning XML</title>
<price>
<retail>39.95</retail>
<discounts>
<amazon>29.99</amazon>
</discounts>
<currency>USD</currency>
</price>
</book>
...
</bookstore>
理想情况下它应该是这样的:
old-gregg$ magic bookstore.xml amazon
/bookstore/book/price/discounts/amazon
最佳答案
我找到了 XMLStarlet它正是我在这里寻找的。使用 Homebrew 安装它:
$ brew update
$ brew install xmlstarlet
$ xml el bookstore.xml | grep amazon
/bookstore/book/price/discounts/amazon
关于xml - 从命令行列出 XML 节点的 XPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12012352/