从XML :: Simple到XML :: Twig的转换未得到相同的结果

时间:2019-01-14 21:46:22

标签: xml perl xml-twig xml-simple

我必须在现有代码中将XML :: Simple替换为XML :: Twig。

正在读取的文件:

<instance name="instance_1">

   <remediation type="scan_src_ip" name="scan_src_ip">
     <config>
       <string name="action">Scan</string>
     </config>
   </remediation>


</instance>

带有XML :: Simple:的旧Perl代码

my $config_xml = XMLin( $CONFIG_FILE,
                            ForceArray => [ 'remediation', 'network_li' ] );
print(Dumper($config_xml));

打印:

$VAR1 = {
      'name' => 'instance_1',
      'remediation' => {
                       'scan_src_ip' => {
                                        'type' => 'scan_src_ip',
                                        'config' => {
                                                    'string' => {
                                                                'content' => 'Scan',
                                                                'name' => 'action'
                                                              }
                                                  }
                                      }
                     }
    };

带有XML :: Twig的新代码:

my $twig = XML::Twig->new();
$twig->parsefile($CONFIG_FILE);
my $config_xml = $twig->simplify(forcearray => [ 'remediation', 'network_li' ]);
print(Dumper($config_xml));

输出为:

$VAR1 = {
      'remediation' => {
                       'scan_src_ip' => {
                                        'type' => 'scan_src_ip',
                                        'config' => {
                                                    'string' => {
                                                                'action' => {
                                                                            'content' => 'Scan'
                                                                          }
                                                              }
                                                  }
                                      }
                     }
    };

我不明白XMLIn的输出为何与twig不同。 为了使它与XMLIn完全相同,我在树枝中缺少什么选择?

任何帮助将不胜感激。

0 个答案:

没有答案