我想用perl更新xml中的属性。这里的问题是当我更新xml的属性时它正在发生,但xml格式正在发生变化.Breaking我的头,但没用!perl代码来更新xml中的属性而不影响xml格式
任何人都可以请建议我一些Perl代码了影响XML格式
我用Perl代码如下所示
#!/usr/bin/perl
use strict;
use warnings;
use XML::Simple;
my $xml_file = '3.xml';
my $xml = XMLin(
$xml_file,
KeepRoot => 1,
ForceArray => 1
);
$xml->{outer1}->[0]->{inner1}->[1]->{name}->[0]->{first} = 'Shane Bond';
XMLout(
$xml,
KeepRoot => 1,
NoAttr => 1,
OutputFile => $xml_file,
);
输入XML更新XML属性:
<outer1>
<inner1>
<name>Stonecold</name>
<org>wwf</org>
<profession>
<Bowler>hai</Bowler>
</profession>
</inner1>
<inner1>
<name first = "Shanebond" />
<org>newzealand</org>
<profession>Shane Bond</profession>
</inner1>
<inner1>
<name>brain schemidit</name>
<org>Google</org>
<profession>Chairman</profession>
</inner1>
</outer1>
预期产量xml:
<outer1>
<inner1>
<name>Stonecold</name>
<org>wwf</org>
<profession>
<Bowler>hai</Bowler>
</profession>
</inner1>
<inner1>
<name first = "Shane Bond" />
<org>newzealand</org>
<profession>Shane Bond</profession>
</inner1>
<inner1>
<name>brain schemidit</name>
<org>Google</org>
<profession>Chairman</profession>
</inner1>
</outer1>
实际输出XML:
<outer1>
<inner1>
<name>Stonecold</name>
<org>wwf</org>
<profession>
<Bowler>hai</Bowler>
</profession>
</inner1>
<inner1>
<name>
<first>Shane Bond</first>
</name>
<org>newzealand</org>
<profession>Shane Bond</profession>
</inner1>
<inner1>
<name>brain schemidit</name>
<org>Google</org>
<profession>Chairman</profession>
</inner1>
</outer1>
[*?为什么XML ::简单 “望而却步” *](http://stackoverflow.com/questions/33267765/why-is-xmlsimple-discouraged) – Borodin