【问题标题】:xmllint string without --xpath option没有 --xpath 选项的 xmllint 字符串
【发布时间】:2019-02-10 13:20:58
【问题描述】:

我有一个看起来像这样的 xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customer>
    <role>probe</role>
    <ipconfig>yes</ipconfig>
    <hostname>test</hostname>
    <ip>192.168.2.123</ip>
    <gateway>192.168.2.1</gateway>
    <subnet>255.255.254.0</subnet>
</customer>

我在 CentOS7 下有脚本来获取值:

role="$(xmllint --xpath "string(//role)" "${xml_path}")"

这很好用。

现在我必须在 CentOS 6 环境下使用相同的。没有 --xpath 支持,我无法安装它。

实现相同目标的最简单和最简单的方法是什么?

【问题讨论】:

    标签: bash centos6 xmllint


    【解决方案1】:

    这可能有效:

    role=$(echo "cat /customer/role/text()" | xmllint --shell file.xml | grep -v '^/')
    

    输出到变量role:

    探测

    【讨论】:

      猜你喜欢
      • 2012-08-12
      • 2014-12-29
      • 2016-02-22
      • 1970-01-01
      • 1970-01-01
      • 2019-06-20
      • 2021-03-04
      • 1970-01-01
      • 2011-01-14
      相关资源
      最近更新 更多