在 Perl 中使用 XML::Simple 将散列转换为 XML 后内容丢失
Content missing after converting hash to XML using XML::Simple in Perl
代码:
my $test = {
'a' => {
'disabled' => 'false',
'options' => '%build_options',
'mailStatus' => {},
'dependencies' =>{
'test' => {
'platforms' => {},
'name' => 'nightly-regressions',
'preRequisitePlatforms' => {},
'dependType' => 'pass'
},
},
'Above' => 'false',
'options' => {},
'critical' => 'true',
}
};
print XMLout($test, noattr=>1, KeepRoot=>1, RootName=>undef, NoEscape => 1);
当我 运行 上面的代码将散列转换为 xml 时,缺少一级“测试”,我得到的输出 xml 是:
输出:
<a>
<Above>false</Above>
<critical>true</critical>
<dependencies>
<name>nightly-regressions</name>
<dependType>pass</dependType>
<platforms></platforms>
<preRequisitePlatforms></preRequisitePlatforms>
</dependencies>
<disabled>false</disabled>
<mailStatus></mailStatus>
<options></options>
</a>
谁能帮我找出我的代码有什么问题?
尝试使用严格选项导入 XML::Simple:
use XML::Simple qw(:strict);
您会发现缺少 KeyAttr 选项的值:
print XMLout($test, noattr=>1, KeepRoot=>1, RootName=>undef, NoEscape=>1, KeyAttr=>[]);
代码:
my $test = {
'a' => {
'disabled' => 'false',
'options' => '%build_options',
'mailStatus' => {},
'dependencies' =>{
'test' => {
'platforms' => {},
'name' => 'nightly-regressions',
'preRequisitePlatforms' => {},
'dependType' => 'pass'
},
},
'Above' => 'false',
'options' => {},
'critical' => 'true',
}
};
print XMLout($test, noattr=>1, KeepRoot=>1, RootName=>undef, NoEscape => 1);
当我 运行 上面的代码将散列转换为 xml 时,缺少一级“测试”,我得到的输出 xml 是:
输出:
<a>
<Above>false</Above>
<critical>true</critical>
<dependencies>
<name>nightly-regressions</name>
<dependType>pass</dependType>
<platforms></platforms>
<preRequisitePlatforms></preRequisitePlatforms>
</dependencies>
<disabled>false</disabled>
<mailStatus></mailStatus>
<options></options>
</a>
谁能帮我找出我的代码有什么问题?
尝试使用严格选项导入 XML::Simple:
use XML::Simple qw(:strict);
您会发现缺少 KeyAttr 选项的值:
print XMLout($test, noattr=>1, KeepRoot=>1, RootName=>undef, NoEscape=>1, KeyAttr=>[]);