我正在尝试使用 Perl XML::LibXML::reader module 解析 xml 文档。该模块运行良好,我能够解析大部分文档,但是 xml 中的某些部分可能在不同级别上有多个具有相同名称的元素,我不知道如何处理和处理这些元素,
我想要做的是将下面的 strcutre 转换为方便的 perl 数据结构我尝试使用XML::Simple和XML::Twig smplify 子例程(见下文)除了 XML::LibXML 但用它们解析本节是非常慢(比没有它们解析文档慢 20 倍),
my @conf= eval{($copy->findnodes('criteria'))};
my $t= XML::Twig->new();
my $hash=$t->parse($_->toString)->simplify(forcearray =>1 ]);
$t->purge();
有人可以建议我如何解析以下部分以更快地使用 XML::LibXML::reader 来实现 perl 数据结构。任何帮助不胜感激
example of such file :
<criteria operator="OR">
<criteria operator="AND"> -> nested element
<criterion test_ref="oval:org.mitre.oval:tst:123" comment="Windows XP is installed"/>
<criterion test_ref="oval:org.mitre.oval:tst:234" comment="file foo.txt exists"/>
<criteria operator="OR"> -> nested element
<criterion test_ref="oval:org.mitre.oval:tst:127" comment="file x.txt exists"/>
<criterion test_ref="oval:org.mitre.oval:tst:127" comment="file y.txt exists"/>
</criteria>
</criteria>
<criteria operator="AND" negate="true"> ->nested element
<criterion test_ref="oval:org.mitre.oval:tst:345" comment="Windows 2003 is installed"/>
<criterion test_ref="oval:org.mitre.oval:tst:456" comment="file fred.txt has a version less than 2"/>
<criterion test_ref="oval:org.mitre.oval:tst:567" negate="true" comment=patch is installed"/>
</criteria>
<criterion test_ref="oval:org.mitre.oval:tst:345" comment="Windows 2003 is installed"/>
</criteria>