パフォーマンス ベンチマークを作成しました: XMLReader vs DOMDocument
XMLReader.php:
$script_starttime = microtime(true);
libxml_use_internal_errors(true);
$xml = new XMLReader;
$xml->open($_FILES["file"]["tmp_name"]);
$xml->setSchema($xmlschema);
while (@$xml->read()) {};
if (count(libxml_get_errors ())==0) {
echo 'good';
} else {
echo 'error';
}
echo '<br><br>Time: ',(microtime(true) - $script_starttime)*1000," ms, Memory: ".memory_get_usage()." bytes";
DOMDocument.php:
$script_starttime = microtime(true);
libxml_use_internal_errors(true);
$xml = new DOMDocument();
$xmlfile = $_FILES["file"]["tmp_name"];
$xml->load($xmlfile);
if ($xml->schemaValidate($xmlschema)) {
echo 'good';
} else {
echo 'error';
}
echo '<br><br>Time: ',(microtime(true) - $script_starttime)*1000," ms, Memory: ".memory_get_usage()." bytes";
私の例: 258.230 行の 18 MB xml
結果:
XMLReader - 656.14199638367 ミリ秒、379064 バイト
DOMDocument - 483.04295539856 ミリ秒、369280 バイト
そこで、DOMDocument を使用することにしましたが、独自の xml と xsd で試して、より高速な選択を使用してください。