【发布时间】:2013-03-04 18:24:24
【问题描述】:
我创建了DOMDocument元素,多次调用appendChild()等等。
在我完成构建 XML 后,我想validate it against an XSD schema。
$newDocument->schemaValidate($schemaPath);
我有错误
No matching global declaration available for the validation root.
但是,如果我将生成的 XML 保存到文件中,请打开它并验证一切正常。或者,如果执行以下操作:
$newDocument->loadXML($newDocument->saveXML());
然后一切都很好。
你能解释一下,为什么验证器在第一种情况下找不到根元素?
更新
我如何构建我的 xml:
$newDocument = new DOMDocument();
$rootElement = $newDocument->createElement('ONIXMessage');
$rootElement->setAttribute('xmlns', 'http://www.editeur.org/onix/2.1/reference');
$newDocument->appendChild($rootElement);
在我将子元素添加到根元素后,但当我尝试根据 XML 架构对其进行验证时,即使列出的代码也会产生错误。
关于 xml 架构文件。我从 EDItEUR 组织下载了它,所以我相信问题就在我这边。链接到网站上的 .xsd 文件http://www.editeur.org/onix/2.1/reference/ONIX_BookProduct_Release2.1_reference.xsd
【问题讨论】:
-
由于您没有展示如何构建 XML 或 XSD 架构,因此根本无法回答您的问题。我建议您与现有的问答材料进行比较,这些材料至少似乎与有关该问题的一些实际信息相关:No matching global declaration available for the validation root
标签: php xml xsd domdocument