![](/img/trans.png)
[英]How to disable warning produced by DOMDocument::schemaValidate() when the schema is invalid?
[英]DOMDocument::schemaValidate() throwing warning errors
我有兩個文件:
要根據模式驗證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]:元素'標題':不期望此元素。 預計是(路由)
我一直故意搞砸我的XML文件,只是為了看看$ dom-> schemaValidate如何實際處理它。 顯然,當XML不符合架構時,我不希望PHP將警告消息吐出到頁面上。 相反,我希望我的應用程序能夠處理這個問題。 我在這里俯瞰什么嗎?
你必須打電話
libxml_use_internal_errors(true);
在創建新的DOMDocument()之前,為了抑制警告並開始將XML解析錯誤收集到可通過libxml_get_errors()訪問的內部結構中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.