验证XML对XSD的问题 - PHP / schemaValidate

时间:2011-08-05 12:25:15

标签: php xml xsd domdocument

我正在尝试使用schemaValidate(String file)中的函数DOMDocument针对XSD验证XML文件。 当我在其他工具(如在线验证器)上验证它时,它工作正常,但在我的程序中,我总是收到此错误,实际上无法找到它来自哪里:

Warning: DOMDocument::schemaValidate(/home/public_html/product/xxxx/xxxx/xxxxx/xsd/AdlSchema.xsd): failed to open stream: Permission denied in /home/public_html/xxxx/xxxx.php on line 209 Warning: DOMDocument::schemaValidate(): I/O warning : failed to load external entity "/home/public_html/product/xxxx/xxxx/xxxx/xxxx/xsd/AdlSchema.xsd" in /home/public_html/xxxx/xxxx.php on line 209 Warning: DOMDocument::schemaValidate(): Failed to locate the main schema resource at '/home/public_html/product/xxxxx/xxxxx/xxxxx/xxxx/xsd/AdlSchema.xsd'. in /home/public_html/xxxx/xxxxx.php on line 209 Warning: DOMDocument::schemaValidate(): Invalid Schema in /home/public_html/xxxx/xxxx.php on line 209

所以我的问题是,有没有办法通过DOMDocument函数获取有关此错误的更多详细信息(主要是Invalid schema one)?如果有人能说出什么可能会导致那种错误的错误(xml和xsd是一种保密,抱歉,但是再一次使用其他一些工具就可以了。)

谢谢!

3 个答案:

答案 0 :(得分:1)

/home/public_html/product/xxxx/xxxx/xxxxx/xsd/AdlSchema.xsd):无法打开流:权限被拒绝
php进程没有必要访问xsd文件的权限。


让我们逛一下并添加一些调试/信息代码 请添加

/* debug code start. Don't forget to remove */
// if there already is a variable you use as parameter for schemaValidate() use that instead of defining a new one.
$path = '/home/public_html/product/xxxx/xxxx/xxxxx/xsd/AdlSchema.xsd';
foreach( array('file_exists', 'is_readable', 'is_writable') as $fn ) {
    echo $fn, ': ', $fn($path) ? 'true':'false', "<br />\n";
}
$foo = stat($path);
echo 'mode: ', $foo['mode'], "<br />\n";
echo 'uid: ', $foo['uid'], "<br />\n";
echo 'gid: ', $foo['gid'], "<br />\n";
if ( function_exists('getmyuid') ) {
    echo 'myuid: ', getmyuid(), "<br />\n";
}
if ( function_exists('getmygid') ) {
    echo 'myuid: ', getmygid(), "<br />\n";
}

$foo = fopen($path, 'rb');
if ( $foo ) {
    echo 'fopen succeeded';
    fclose($foo);
}
else {
    echo 'fopen failed';
}
/*  debug code end */

在你调用schemaValidate()之前。

答案 1 :(得分:0)

我使用XML和XSD架构文件的相对路径遇到了同样的问题。但是在我把它改成绝对的之后,问题就消失了。

答案 2 :(得分:0)

对我来说,原因是禁用了libxml实体加载器(libxml_disable_entity_loader(true);)。似乎必须启用此功能。我切换到DOMDocument::validateSchemaSource是因为我不想启用实体加载器。

相关问题