我想迭代XML中的所有子元素。
可以动态迭代吗?换句话说,我想在不知道最后一个元素号的情况下检查/编辑所有嵌套元素。
For eg:
在下面的"server-groups"元素中,包含三个服务器组子元素。我想在不知道计数的情况下迭代所有的服务器组元素。现在是三点。这样我才能访问最后一个元素。如果我不知道最后一个元素数,可以迭代吗?
<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>发布于 2015-11-11 11:33:11
在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 nodeshttps://stackoverflow.com/questions/33649190
复制相似问题