在Perl中使用XML::Simple将哈希转换为XML后缺少内容

在Perl中使用XML::Simple将哈希转换为XML后缺少内容,xml,perl,hash,Xml,Perl,Hash,代码: my $test = { 'a' => { 'disabled' => 'false', 'options' => '%build_options', 'mailStatus' => {}, 'dependencies' =>{ 'te

代码:

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);
<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时,缺少一级“测试”,我得到的输出xml是:

输出:

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);
<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和strict选项:

使用XML::Simple qw(:strict);
您将发现缺少KeyAttr选项的值:

print XMLout($test,noattr=>1,KeepRoot=>1,RootName=>unde,NoEscape=>1,KeyAttr=>[]);

使用
XML::Simple
有什么好的理由吗?“请不要在新代码中使用此模块…”这是否回答了:您的问题?不要使用XML::Simple。别这样!这是对时间的巨大浪费,也是问题的根源。为什么人们不相信一个模块的文档,因为它太坏了而警告使用该模块?