Problem validating XML against XSD - PHP/schemaValidate
I'm trying to validate an XML file against an XSD using the function schemaValidate(String file)
from DOMDocument
.
When I validate it on other tools like online validators, it works fine, but in my program I always get this error and really can't find where it's coming from:
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 2开发者_运维技巧09 Warning: DOMDocument::schemaValidate(): Invalid Schema in /home/public_html/xxxx/xxxx.php on line 209
So my question is, is there a way to get more details about this error (mainly the Invalid schema one) with DOMDocument functions? and if ever someone could tell what could cause that kind of errors that would be great (xml and xsd are kind of confidentials, sorry, but once again it is working just fine with a few other tools).
Thanks!
/home/public_html/product/xxxx/xxxx/xxxxx/xsd/AdlSchema.xsd): failed to open stream: Permission deniedThe php process doesn't have the necessary rights to access the xsd file.
Let's poke around a little bit and add some debug/info code Please add
/* 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 */
right before your call to schemaValidate().
I got the same problem using relative paths to XML and XSD schema files. But after I changed it to the absolute ones the problem disappeared.
For me the reason was that the libxml entity loader was disabled (libxml_disable_entity_loader(true);
). It seems to have to be enabled to use this function. I switched to DOMDocument::validateSchemaSource
since I don't want to have to enable the entity loader.
精彩评论