【问题标题】:How Navigate XML with augeas xml如何使用 augeas xml 导航 XML
【发布时间】:2016-08-11 14:34:06
【问题描述】:

我有一个非常奇怪的 xml 文件,我需要使用 augeas 对其进行更新。

<root>
    <node name="Client">
        <node name="Attributes">
            <info>
                <test>
                    <entry><key>colour</key><value type="string">blue</value></entry>
                </test>
            </info>
        </node>
    </node>
    <node name="Network">
        <node name="Server">
            <info>
                <test>
                    <entry><key>transport</key><value type="string">internet</value></entry>
                    <entry><key>ipAddr</key><value type="string">125.125.125.142</value></entry>
                    <entry><key>portNo</key><value type="string">1234</value></entry>
                    <entry><key>protocolType</key><value type="string">tcp</value></entry>
                </test>
            </info>
        </node>
    </node>
</root>

我需要更新包含文本 ipAddr 的元素“key”之后的元素“value”。

【问题讨论】:

    标签: ruby xml xpath puppet augeas


    【解决方案1】:

    根据您对要更新的节点的描述,建议如下:

    set /files/path/to/your/file.xml//entry[key/#text="ipAddr"]/value/#text "255.255.255.0"
    

    这会选择文件中任何级别的entry 节点,该节点有一个key/#text 子节点,其值为ipAddr,然后将其value/#text 子节点更新为值为255.255.255.0

    【讨论】:

    • 这给了我 ipAddr255.255.255.0125.125.125.142 entry> 而不是 ipAddr255.255.255.0
    • @Vash,我无法重现。答案似乎对我描述的示例文件有效 - 检查您是否正确复制了它?
    • 它的工作原理我把方括号放在了错误的地方。干杯!
    猜你喜欢
    • 1970-01-01
    • 2019-08-03
    • 2019-08-14
    • 2017-04-19
    • 2013-12-10
    • 2011-08-08
    • 1970-01-01
    • 2013-11-18
    • 1970-01-01
    相关资源
    最近更新 更多