3

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.

kenorb
  • 155,785
  • 88
  • 678
  • 743
Dakkar
  • 5,682
  • 5
  • 22
  • 28

1 Answers1

7

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.

raphink
  • 3,625
  • 1
  • 28
  • 39
  • How can I check insert a new XML element with above attribute if it does not exist, and modify the XML element with the above attribute if it does exist? – fruitJuice May 05 '15 at 23:59