Mil*_*loš 9 php xml dtd xml-validation
我用我在本地的DTD文件来验证我的XML.
为此,我正在做:
$xml = $dmsMerrin.'/xml/'.$id.'/conversion.xml';
$dtd = $dmsMerrin.'/style_files/journalpublishing.dtd';
$dom = new DOMDocument();
@$dom->load($xml);
libxml_use_internal_errors(true);
if (@$dom->validate()) {
$htmlDTDError .= "<h2>No Errors Found - The tested file is Valid !</h2>";
}
else {
$errors = libxml_get_errors();
$htmlDTDError .= '<h2>Errors Found ('.count($errors).')</h2><ol>';
foreach ($errors as $error) {
$htmlDTDError .= '<li>'.$error->message.' on line '.$error->line. '</li>';
}
$htmlDTDError .= '</ol>';
libxml_clear_errors();
}
libxml_use_internal_errors(false);
Run Code Online (Sandbox Code Playgroud)
对于1600行的XML,这需要大约30秒.
这是平时吗?我认为应该快得多吗?
如您所见,我使用的DTD是本地服务器上的.
任何的想法?谢谢.
编辑:通过调试和检查执行时间,我注意到如果我的xml有1600行或150行,它需要相同的时间,所以问题不是xml大小.
And this takes about 30sec for an XML with 1600 lines.
That's an unusually long time, and it's likely due to misconfiguration.
By debuging and checking the execution time, I noticed that it takes the same time if my xml has 1600 lines or 150 lines, so the problem is not the xml size.
For a tool that may provide more diagnostics here, try xmllint --valid. It will show, for example, errors for any DTDs that could not be retrieved.
It's very likely that the extra time is due to fetching resources, such as the DTD, needed to perform validation.
curl对于您的其中一个文件,请通过使用类似来自同一服务器的工具进行测试来确认可以快速检索 DTD 的 URL 。它是一个复杂的 DTD 吗?是否会引入其他文件?特别是,请确保它永远不会引用必须从网络获取的资源,或者使用 DNS 解析缓慢的主机名。