augeas: update xml value based on previous tag

asked 2017-06-09 09:38:07 -0600

rajeevsharma gravatar image

Hi, I have a simple issue while updating xml file but I'm not able to find the solution after trying many things out. I am trying to update password based on the username which is defined in just previous tag of password tag. My xml file is below:

<ns2:tokens xmlns:ns2="www.t-systems.de/bud/token/tokenmap">
    <token>
        <name>user1</name>
        <value>pass1</value>
    </token>
    <token>
        <name>user2</name>
        <value>pass2</value>
    </token>
    <token>
        <name>user3</name>
        <value>pass3</value>
    </token>

</ns2:tokens>

Here, based on the username in <name> tag I need to update password in <value> tag. I have tried following but it's not working:

augeas {'Update external.xml':
  incl    => '/tmp/external.xml',
  context => '/files/tmp/external.xml/ns2:tokens',
  lens    => "xml.lns",
  changes => ["set /files/external.xml/token/[name/#text='user2'/name]/value/#text newpass2",]
  }

Any idea?

edit retag flag offensive close merge delete