【发布时间】:2021-03-20 08:06:45
【问题描述】:
这是我的问题,我在 UNIX 上工作,我有一个包含在字符串 foo 中的 xml 文件:
echo $foo
<a> <b> <c> bar </c> </b> </a>
我想得到值bar。 我可以使用 xmllint 但我没有 --xpath 选项。 并不是说 foo 是 UNIX 变量而不是文件。
我找到的唯一解决方案是运行:
echo $foo | xmllint --shell <(cat) <<<'xpath a/b/c/text()'
但它会产生非常冗长的输出:
/ > Object is a Node Set :
Set contains 1 nodes:
1 TEXT
content= bar
/ >
我只想得到“酒吧”。 感谢您的帮助!
【问题讨论】:
-
出于好奇:你怎么“没有 --xpath 选项”?另外,你能用其他有它的东西吗?
-
我有一个非常旧的 xmllint 版本...