The XML file is as follows:
<?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>
And my code is:
#!/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);
My question is, if the XML file is only 80 MB, then the program will be very fast, but when the XML file is much larger, the program can be very slow. Can someone help me speed this up, please?
source share