DOMDocument :: schemaValidate () throwing warnings

I have two files:

  • Sample XML file.
  • The .xsd w / schema file to which the specified XML file should follow.

To check the XML file for the schema, I used:

$dom = new DOMDocument();

//$this->xmlstr; is my XML file after being loaded into a string.
$dom->loadXML($this->xmlstr); 

//$xsd_file is definitely my xsd file.
if(!$dom->schemaValidate($xsd_file)){
     $errors = libxml_get_errors(); //supposed to give back errors?
     var_dump($errors); //debugging - shows: array empty
}

However, I keep getting warnings when my XML document does not adhere to the rules in the schema.

Warning: DOMDocument :: schemaValidate () [domdocument.schemavalidate]: Title element: this element is not expected. Expected (Routing)

I intentionally twisted my XML file, just to find out how it really handles $ dom-> schemaValidate. Obviously, I do not want PHP to display warning messages on the page whenever XML does not match the schema. Instead, I want my application to take care of this. Did I forget something?

+5
1

libxml_use_internal_errors(true);

DOMDocument() XML , libxml_get_errors().

+8

All Articles