2
我試圖讓錯誤數量在這個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