I have an xml document similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<example>
<member name="dbsettings">
<node name="username"><![CDATA[someusername]]></node>
<node name="password"><![CDATA[mypassword]]></node>
</member>
<member name="sitesettings">
<node name="title"><![CDATA[just a title]]></node>
</member>
</example>
And I'm trying to update these settings in puppet using the following augeas command:
set example/member[#attributes/name='dbsettings']/node[#attributes/name='username']/#text anotherusername
What I expect it to do is to replace the entire contents of the node by "anotherusername" instead it just appends it resulting in:
<node name="username"><![CDATA[someusername]]>anotherusername</node>
How can I select and update the contents of the CDATA element using augeas or remove it without removing the actual node itself? (the real node contains more attributes which I don't want to hard-code in)
Augtool can show you what the tree looks like actually:
$ augtool -At "Xml incl /test.xml" -r .
augtool> set /augeas/context /files/test.xml
augtool> print example/member[#attribute/name='dbsettings']/node[#attribute/name='username']
/files/test.xml/example/member[1]/node[1]
/files/test.xml/example/member[1]/node[1]/#attribute
/files/test.xml/example/member[1]/node[1]/#attribute/name = "username"
/files/test.xml/example/member[1]/node[1]/#CDATA = "someusername"
This shows two things:
#attribute
, without a 's'#CDATA
subnodeHence your command should be:
set example/member[#attribute/name='dbsettings']/node[#attribute/name='username']/#CDATA anotherusername