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

Dak*_*kar 3 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>
Run Code Online (Sandbox Code Playgroud)

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

augtool> set /files/test.xml/configuration/properties/property[1]/#text NEWUSER
Run Code Online (Sandbox Code Playgroud)

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

augtool> match /files/test.xml/configuration/properties/*/#attribute/name  username
Run Code Online (Sandbox Code Playgroud)

工作得很好

/files/test.xml/configuration/properties/property[1]/#attribute/name
Run Code Online (Sandbox Code Playgroud)

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

ℝap*_*ink 7

你需要做的是:

set /files/test.xml/configuration/properties/property[#attribute/name='username']/#text NEWUSER
Run Code Online (Sandbox Code Playgroud)

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