您好,我正在尝试插入一个新元素,以便从这里开始
<explicit-group name="CDEV">
<aip-address>1.1.1.1</aip-address>
<aip-address>2.2.2.2</aip-address>
<aip-address>3.3.3.3</aip-address>
对此
<explicit-group name="CDEV">
<aip-address>1.1.1.1</aip-address>
<aip-address>2.2.2.2</aip-address>
<aip-address>3.3.3.3</aip-address>
<aip-address>99.99.99.254</aip-address>
我拥有的代码如下,但我已经阅读了两天的引用和取消引用,但仍然无法得到它。我是在尝试做一些不可能的事情,还是有人可以告诉我如何做。
谢谢!
use strict;
use XML::Simple;
use Data::Dumper;
my $xs = XML::Simple->new(
XMLDecl => '<?xml version="1.0" encoding="UTF-8"?>',
forcearray => [ 'item' ],
keyattr => { },
rootname => 'SG-distribution',
);
my $opt = $xs->XMLin(\*DATA);
push @{ $opt->{'sa-coller'}->{'explicit-group'} } , { {'CDEV'}->{'aip-address'} };
print Dumper($opt);
print $xs->XMLout($opt);
__DATA__
<?xml version="1.0" encoding="UTF-8"?><SG-distribution>
<sa-coller name="W8-C1" enabled="true" host="localhost" port="99">
<ip-group name="home" ipAddressMask="192.168.0.*" match="glob"/>
<ip-group name="home2" ipAddressMask="10.0.0.*" match="glob"/>
<explicit-group name="CDEV">
<aip-address>1.1.1.1</aip-address>
<aip-address>2.2.2.2</aip-address>
<aip-address>3.3.3.3</aip-address>
</explicit-group>
<explicit-group name="HYU"/>
<explicit-group name="JUN"/>
</sa-coller>
</SG-distribution>