我有6个XML文档需要用PHP解析。 每个文件都有50000个元素因此我需要快速解析器所以我选择了DOMDocument类。 XML文件的例子是: p>
<?xml version =“1.0”encoding =“ UTF-8“standalone =”yes“?>
< ns2:PinsCountryCodeIds xmlns:ns2 =”http://apis-it.hr/umu/2015/types/kp“>
< ns2:PinCountryCodeId&gt ;
< ns2:CountryCodeId> HR< / ns2:CountryCodeId>
< ns2:PinPrimatelja> 000000000< / ns2:PinPrimatelja>
< / ns2:PinCountryCodeId>
< ns2:PinCountryCodeId>
< ns2:CountryCodeId> HR< / ns2:CountryCodeId>
< ns2:PinPrimatelja> 000000001< / ns2:PinPrimatelja>
< / ns2:PinCountryCodeId>
< ns2:PinCountryCodeId>
< ns2 :CountryCodeId> HR< / ns2:CountryCodeId>
< ns2:PinPrimatelja> 000000002< / ns2:PinPrimatelja>
< / ns2:PinCountryCodeId>
< / ns2:PinsCountryCodeIds>
code> pre>
我提出的最好的是这段代码: p>
$ in put_file = scandir($ OIB_path); //扫描文件目录
foreach($ input_file as $ input_name){
if($ input_name ==“。”|| $ input_name ==“..”)
continue;
$ OIB_file = $ OIB_path。 $ input_name;
$ doc = new DOMDocument();
$ doc-> load($ OIB_file);
$ doc-> saveXML();
foreach($ doc-> getElementsByTagNameNS('http://apis-it.hr/umu/2015/types/kp','PinPrimatelja')as $ element){
echo $ element-> nodeValue,',< br> ';
}
}
code> pre>
但它太慢,解析6个文件需要20多分钟。 p>
\ n
我可以做些什么来改进它? p>
div>