2

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(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 "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 'product/xxxxx/xxxxx/xxxxx/xxxx/xsd/AdlSchema.xsd'. in xxxx/xxxxx.php on line 209
Warning: DOMDocument::schemaValidate(): Invalid Schema in 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).

1
  • The first error says permission is denied to the schema file. Are you sure this is not the problem? Commented Aug 5, 2011 at 12:28

3 Answers 3

2

/home/public_html/product/xxxx/xxxx/xxxxx/xsd/AdlSchema.xsd): failed to open stream: Permission denied
The 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().

Sign up to request clarification or add additional context in comments.

5 Comments

it does have the necessary rights (own and grp to apache, mod 755). And I just tried the libxml_use_internal_errors(true) and here is what I get [1] (Code 1549) in on line 0 column 0 XML error "Failed to locate the main schema resource at '/home/public_html/product/xxxx/xxxxx/xxxx/xxxx/xsd/AdlSchema.xsd'. "
sorry, but failed to open stream: Permission denied is quite unequivocal ;-)
ya I agree... but I set all the permissions right and I still get the error I really don't understand...
added some debug script snippet.
well it is working now, I don't know what I changed exactly but for sure it was an access problem... thanks for the debug code, really helpful
0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.