如何用augeas改变属性值,这些位置改变了XML?

时间:2013-06-04 13:03:33

标签: xml puppet augeas

我有以下问题:

我的XML(简化):

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <properties>
    <property name="username">USERNAME</property>
    <property name="anything">blabla</property>
  </properties>
</configuration>

我需要用augeas替换Username值。 它适用于:

augtool> set /files/test.xml/configuration/properties/property[1]/#text NEWUSER

但问题是:用户名条目并不总是在第一位。在augeas中有没有办法用“匹配”或某种正则表达式来寻找位置?

augtool> match /files/test.xml/configuration/properties/*/#attribute/name  username

中效果很好
/files/test.xml/configuration/properties/property[1]/#attribute/name

但我在设置值时不知道如何使用此信息。

1 个答案:

答案 0 :(得分:7)

您需要做的是:

set /files/test.xml/configuration/properties/property[#attribute/name='username']/#text NEWUSER

这将选择/files/test.xml/configuration/properties/property子节点与#attribute/name匹配的属性(username),并将其#text子节点设置为NEWUSER

相关问题