Reputation: 5952
I have the following problem:
my XML (simplified):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<properties>
<property name="username">USERNAME</property>
<property name="anything">blabla</property>
</properties>
</configuration>
I need to replace the Username value with augeas. It works fine with:
augtool> set /files/test.xml/configuration/properties/property[1]/#text NEWUSER
But the problem is: The username entry is NOT always on position one. Is there a way in augeas to look for the position with "match" or some kind of regex?
augtool> match /files/test.xml/configuration/properties/*/#attribute/name username
works fine an results in
/files/test.xml/configuration/properties/property[1]/#attribute/name
But i don't know how to use this information when setting a value.
Upvotes: 3
Views: 3933
Reputation: 3665
What you need to do is:
set /files/test.xml/configuration/properties/property[#attribute/name='username']/#text NEWUSER
This selects the property (/files/test.xml/configuration/properties/property
) whose #attribute/name
subnode matches username
, and sets its #text
subnode as NEWUSER
.
Upvotes: 7