[英]DOMDocument::schemaValidate() throwing warning errors
I have two files: 我有两个文件:
To validate the XML file against the schema, I've been using: 要根据模式验证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
}
However, I keep getting warning errors whenever my XML doc doesn't adhere to the rules in the schema. 但是,每当我的XML文档不符合架构中的规则时,我就会不断收到警告错误。
Warning: DOMDocument::schemaValidate() [domdocument.schemavalidate]: Element 'Header': This element is not expected.
警告:DOMDocument :: schemaValidate()[domdocument.schemavalidate]:元素'标题':不期望此元素。 Expected is ( Routing )
预计是(路由)
I've been intentionally screwing up my XML file, just to see how $dom->schemaValidate actually handles it. 我一直故意搞砸我的XML文件,只是为了看看$ dom-> schemaValidate如何实际处理它。 Obviously, I don't want PHP spitting out warning messages onto the page whenever the XML doesn't meet the schema.
显然,当XML不符合架构时,我不希望PHP将警告消息吐出到页面上。 Instead, I'd like my app to take care of that.
相反,我希望我的应用程序能够处理这个问题。 Am I overlooking something here?
我在这里俯瞰什么吗?
You must call 你必须打电话
libxml_use_internal_errors(true);
before creating new DOMDocument() in order to suppress warnings and start collecting XML parsing errors into internal structure accessible via libxml_get_errors(). 在创建新的DOMDocument()之前,为了抑制警告并开始将XML解析错误收集到可通过libxml_get_errors()访问的内部结构中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.