2

我正在使用 augeas 在某些机器上操作 XML。虽然创建新节点并设置一堆属性就像一种魅力,但我正在为向 XML 文件添加一个简单的属性而苦恼。XML 如下所示:

<?xml version="1.0"?>
<Context>
   <WatchedResource></WatchedResource>
</Context>

我不只是试图通过添加allowLinking="true"到上下文根节点

set /files/path/to/my/file.xml/Context/#attribute/allowLinking "true"

不幸的是,这总是失败

/error = "put_failed"
/error/path = "/files/path/to/my/file.xml/Context"
/error/lens = "/usr/share/augeas/lenses/dist/xml.aug:134.10-.73:"
/error/message = "Failed to match \n    { /#attribute/ }?({ /#text/ …

我正在使用 puppet 开源 3.4.2 和 augeas 1.0.0。

任何建议我做错了什么?

4

1 回答 1

3

顺序在 Augeas 树中很重要。在这种情况下,需要在#text节点和子节点之前设置 XML 节点属性。

所以你需要的是:

ins #attribute before /files/test.xml/Context/#text
set /files/test.xml/Context/#attribute/allowLinking true

请注意,此更改不是幂等的,因为insert它不是幂等操作。

在 Puppet 上,您可以使用它onlyif来使其具有幂等性。

于 2014-01-22T18:54:08.270 回答