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文件必须遵守该文件
$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()访问的内部结构中