Perl的XML :: DOM解析器使用
问题描述:
我试图让错误数量在这个XML文件的第五行:Perl的XML :: DOM解析器使用
<summary>
<result usecase="CRUD" target="AppHost">
<testcase size="1" cvus="1">
<sequence tps="0.25" totaltx="1" name="CRUD" min="3515" max="3515" errors="0" average="3515.0">
<node tps="0.25" totaltx="1" name="localhost" min="3515" max="3515" errors="0" average="3515.0">
[…]
</node>
</sequence>
</testcase>
</result>
</summary>
使用XML DOM :: ::解析器和验证码:
my $parser = new XML::DOM::Parser;
my $doc = $parser->parsefile($file);
my $root = $doc->getDocumentElement();
foreach my $child ($root->getChildNodes) {
print $child->getNodeName();
print "\n";
}
但不是唯一的印刷“结果”,我得到这个:
#text
result
#text
为了达到第5行的“节点”节点的参数,我想用getFirstChild
方法,但我不能因为它寻找“#text”的孩子。
这是什么#text对象?我应该怎么做才能到达第五个节点?
谢谢
凯文
答
尝试:
XML DOM ::是非标准的。您应该使用['XML :: LibXML'](http://search.cpan.org/perldoc?XML::LibXML)。 – Axeman 2010-11-14 23:53:36