通过Augeas向XML根节点添加属性的问题 [英] Issues adding attribute to XML root node via augeas

查看:126
本文介绍了通过Augeas向XML根节点添加属性的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Augeas在某些机器上操纵XML.尽管创建新节点并设置一堆属性就像一种魅力,但我很想为XML文件添加一个简单的属性. XML如下所示:

I am using augeas to manipulate XML on some machines. Whereas creating new nodes and also setting a bunch of attributes worked like a charm I'm biting my nails of adding a simple attribute to an XML file. XML looks like the following:

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

我不只是尝试通过

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

不幸的是,这总是失败的

Which is unfortunately always failing with

/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/ …

我正在使用带有augeas 1.0.0的puppet开源3.4.2.

I'm using puppet opensource 3.4.2 with augeas 1.0.0.

有人建议我在做什么错吗?

Any suggestion what I'm doing wrong?

推荐答案

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

Order matters in the Augeas tree. In that case, XML node attributes need to be set before the #text node and the child nodes.

所以您需要的是:

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

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

Note that this change is not idempotent, since insert is not an idempotent operation.

在Puppet上,您可以使用onlyif来使幂等.

On Puppet, you could use onlyif to make this idempotent.

这篇关于通过Augeas向XML根节点添加属性的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆