phpxmlxsddomdocument

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(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).


Solution

  • /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().