如何在Augeas中动态迭代XML元素

时间:2015-11-11 11:02:59

标签: jboss7.x puppet puppet-enterprise augeas

我想迭代XML中的所有子元素。

是否可以动态迭代?换句话说,我想检查/编辑所有嵌套元素,而不知道最后一个元素编号。

例如:

在以下“server-groups”元素中包含三个 server-group 子元素。我想在不知道计数的情况下迭代所有服务器组元素。现在是三。这样我就可以访问最后一个元素了。如果我不知道最后一个元素编号,是否可以迭代?

<server-groups>
    <server-group name="ServiceGroupOne" profile="full-ha">
        <system-properties>
            <property name="jboss.default.multicast.address" value="232.0.2.20" boot-time="true"/>
            <property name="modcluster.proxylist" value="192.168.79.77:7777" boot-time="true"/>
            <property name="modcluster.lbgroup" value="SearchGroupOne" boot-time="true"/>
        </system-properties>
    </server-group>
    <server-group name="ServiceGroupTwo" profile="full-ha">
        <system-properties>
            <property name="jboss.default.multicast.address" value="232.0.2.20" boot-time="true"/>
            <property name="modcluster.lbgroup" value="SearchGroupTwo" boot-time="true"/>
            <property name="modcluster.proxylist" value="192.168.79.77:7777" boot-time="true"/>
        </system-properties>
    </server-group>
    <server-group name="ServiceGroupThree" profile="full-ha">
        <system-properties>
            <property name="modcluster.lbgroup" value="CommonSearchGroup" boot-time="true"/>
            <property name="modcluster.proxylist" value="192.168.79.77:7777" boot-time="true"/>
            <property name="jboss.default.multicast.address" value="232.0.2.20" boot-time="true"/>
        </system-properties>
   </server-group>
</server-groups>

1 个答案:

答案 0 :(得分:1)

在Augeas中,迭代可以使用setm

完成
  COMMAND
    setm - set the value of multiple nodes

  SYNOPSIS
    setm <BASE> <SUB> [<VALUE>]

  DESCRIPTION
    Set multiple nodes in one operation.  Find or create a node matching SUB
    by interpreting SUB as a  path expression relative to each node matching
    BASE. If SUB is '.', the nodes matching BASE will be modified.

  OPTIONS
     <BASE>    the base node
     <SUB>     the subtree relative to the base
     <VALUE>   the value for the nodes