且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 Augeas 更新现有的或创建新的 XML 节点

更新时间:2023-09-13 16:11:58

/files/test.xml/properties/entry[#attribute/key='hello']/#text 没有匹配任何节点,因此 Augeas 创建一个新节点.如果您想更新这两个值.

/files/test.xml/properties/entry[#attribute/key='hello']/#text doesn't match any node, so Augeas creates a new node. If you want to update both values.

显然,您只想保留一个 entry 节点并设置其 text 和 key 属性:

Apparently, you want to keep only one entry node and set both its text and key attribute:

defnode entry /files/test.xml/properties/entry[#attribute/key="foo"]
set $entry/#attribute/key 'hello'
set $entry/#text 'world'