简体   繁体   English

DOMDocument :: schemaValidate()抛出警告错误

[英]DOMDocument::schemaValidate() throwing warning errors

I have two files: 我有两个文件:

  • A sample XML file. 一个示例XML文件。
  • A .xsd file w/ schema, which the aforementioned XML file must adhere to. 带有架构的.xsd文件,前面提到的XML文件必须遵守该文件。

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.

相关问题 当架构无效时,如何禁用DOMDocument :: schemaValidate()生成的警告? - How to disable warning produced by DOMDocument::schemaValidate() when the schema is invalid? 为什么\\ DomDocument#schemaValidate()对有效的XML发出警告? - Why does \DomDocument#schemaValidate() give warning for valid XML? PHP DOMDocument schemaValidate但获取类型 - PHP DOMDocument schemaValidate but get type DOMDocument :: schemaValidate()超出允许的最大长度'255' - DOMDocument::schemaValidate() exceeds the allowed maximum length of '255' 在PHP 5.5.14中要求抛出警告和错误 - require in PHP 5.5.14 throwing warning and errors 如何在PHP中使用schemaValidate()验证XML时将警告消息作为字符串获取? - How to get the warning message as a string when validating XML with schemaValidate() in PHP? 推进DOMDocument :: schemaValidate():元素“外键”,属性“ ondelete”,“ onupdate”,“ skipsql”该属性不允许吗? - propel DOMDocument::schemaValidate(): Element 'foreign-key', attribute 'ondelete','onupdate','skipsql' The attribute is not allowing? 为什么当我加载法语和中文页面时,`DomDocument` 的 `load` 方法会显示类似“Warning DOMDocument::load()”的错误? - Why does the `load` method of `DomDocument` show me errors like "Warning DOMDocument::load()" when I load French and Chinese Page? 为什么相同XML和XSD文件上的DOMDocument :: schemaValidate()有时执行时间比平时高得多? - Why DOMDocument::schemaValidate() over the same XML and XSD files have sometimes a execution time dramatically higher than usual? 奇怪的PHP DOMDocument警告 - Strange PHP DOMDocument Warning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM