Vash Vash - 3 months ago 14
Ruby Question

How Navigate XML with augeas xml

I have a very strange xml file that i need to update using 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>


I need to update the element "value" which is just after the element "key" which contains the text ipAddr.

Answer

Based on your description of the node you want to update, here's a suggestion:

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

This selects the entry node at any level in the file, which has a key/#text subnode with value ipAddr and then it updates its value/#text subnode to have value 255.255.255.0.

Comments