Page 1 of 1

issue validating xml file

Posted: Fri Feb 01, 2008 12:18 pm
by bouncer
hi there.

i'm having some issues validating expt.xml file using this script, expt.xml and expt.xsd are in the same folder

Code: Select all

 
<?php
 
define("myXML","expt.xml");
define("myXSD","expt.XSD");
 
class XML_Eval_From_XSD extends DomDocument
{
    var $xml_var = myXML;
    var $dom = NULL;
    var $SucessMessage = 'Validation was completed with sucess!';
 
    function __construct($opt,$dispErr)
    {
        XML_Eval_From_XSD::setUseErrors($opt);
        parent::__construct();
        XML_Eval_From_XSD::LoadXML_File();
        XML_Eval_From_XSD::Validate();
        XML_Eval_From_XSD::getErrors($dispErr);
    }
 
    private function  setUseErrors($opt=true)
    {
        if(is_bool($opt))
            return libxml_use_internal_errors($opt);
        else
            return false;
    }
 
    public function LoadXML_File()
    {
        if(is_object($this) AND is_file(myXML))
            return parent::load(myXML);
        else
            return false;
    }
 
 
    public function Validate()
    {
        if(is_file(myXSD))
            return parent::schemaValidate(myXSD);
        else
            return false;
    }
 
    public function getErrors($opt='show')
    {
        if(XML_Eval_From_XSD::Validate()===false)
 
        switch($opt){
            case 'show':
                var_dump($this->DocErrors());
                break;
            default:
                echo $this->SucessMessage.myXSD;
        }
    }
 
    private function DocErrors()
    {
        return libxml_get_last_error();
    }
    
}
 
$myEXPT = new XML_Eval_From_XSD(true,'show');
?>
 
this is the error

Code: Select all

 
object(LibXMLError)#2 (6) {
  ["level"]=>
  int(2)
  ["code"]=>
  int(1845)
  ["column"]=>
  int(0)
  ["message"]=>
  string(127) "Element '{urn:OECD:StandardAuditFile-Tax:1.00_01}AuditFile': No m
atching global declaration available for the validation root.
"
  ["file"]=>
  string(51) "file:///C%3A/wamp/www/phpodbc/dev/expt.xml"
  ["line"]=>
  int(2)
}
 
this is the header of my xml file

Code: Select all

 
<AuditFile xmlns="urn:OECD:StandardAuditFile-Tax:1.00_01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="EXPT.XSD" xmlns:doc="urn:schemas-basda-org:schema-extensions:documentation">
 
i hope you can help me.

thanks in advance