XML 文件是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<resource-data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="resource-data.xsd">
<class name="AP">
<attributes>
<resourceId>00 11 B5 1B 6D 20</resourceId>
<lastModifyTime>20130107091545</lastModifyTime>
<dcTime>20130107093019</dcTime>
<attribute name="NMS_ID" value="DNMS" />
<attribute name="IP_ADDR" value="10.11.141.111" />
<attribute name="LABEL_DEV" value="00 11 B5 1B 6D 20" />
</attributes>
<attributes>
<resourceId>00 11 B5 1B 6D 21</resourceId>
<lastModifyTime>20130107091546</lastModifyTime>
<dcTime>20130107093019</dcTime>
<attribute name="NMS_ID" value="DNMS" />
<attribute name="IP_ADDR" value="10.11.141.112" />
<attribute name="LABEL_DEV" value="00 11 B5 1B 6D 21" />
</attributes>
</class>
</resource-data>
我的代码:
#!/usr/bin/perl
use Encode;
use XML::LibXML;
use Data::Dumper;
$parser = new XML::LibXML;
$struct = $parser->parse_file("d:/AP_201301073100_1.xml");
my $file_data = "d:\\ap.txt";
open IN, ">$file_data";
$rootel = $struct->getDocumentElement();
$elname = $rootel->getName();
@kids = $rootel->getElementsByTagName('attributes');
foreach $child (@kids) {
@atts = $child->getElementsByTagName('attribute');
foreach $at (@atts) {
$va = $at->getAttribute('value');
print IN encode("gbk", "$va\t");
}
print IN encode("gbk", "\n");
}
close(IN);
我的问题是,如果 XML 文件只有 80MB,那么程序会非常快,但是当 XML 文件大得多时,程序会非常慢。有人可以帮我加快速度吗?