Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php DOMDocument::schemaValidate()引发警告错误_Php_Xml_Simplexml - Fatal编程技术网

Php DOMDocument::schemaValidate()引发警告错误

Php DOMDocument::schemaValidate()引发警告错误,php,xml,simplexml,Php,Xml,Simplexml,我有两个文件: 示例XML文件 带有模式的.xsd文件,前面提到的XML文件必须遵守该文件 为了根据模式验证XML文件,我一直在使用: $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(!$do

我有两个文件:

  • 示例XML文件
  • 带有模式的.xsd文件,前面提到的XML文件必须遵守该文件
为了根据模式验证XML文件,我一直在使用:

$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
}
但是,每当我的XML文档不符合模式中的规则时,我就会收到警告错误

警告:DOMDocument::schemaValidate()[DOMDocument.schemaValidate]: 元素“Header”:不需要此元素。预期is(路由)

我一直在故意破坏我的XML文件,只是为了看看$dom->schemaValidate如何实际处理它。显然,我不希望PHP在XML不符合模式时在页面上弹出警告消息。相反,我希望我的应用程序能够解决这个问题。我是不是忽略了什么?

你必须打电话给我

libxml_use_internal_errors(true);
在创建新的DOMDocument()之前,为了抑制警告并开始将XML解析错误收集到可通过libxml_get_errors()访问的内部结构中