【问题标题】:How to dynamically iterate XML Element in Augeas如何在 Augeas 中动态迭代 XML 元素
【发布时间】:2015-11-11 11:02:59
【问题描述】:

我想迭代 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>

【问题讨论】:

    标签: jboss7.x puppet puppet-enterprise augeas


    【解决方案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
    

    【讨论】:

    • @Raphink:哇。很酷。但是在这个工具中还有一个挑战。如果你看我的例子,“modcluster.proxylist”键被放置在不同的位置。是否可以一次更改属性的值?如果可能的话,你能解释一下吗?
    • 既然你为此打开了new question,我已经在那里回答了;-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 2016-11-21
    • 1970-01-01
    相关资源
    最近更新 更多