【问题标题】:Can't validate against XSD无法针对 XSD 进行验证
【发布时间】:2013-11-27 12:52:18
【问题描述】:

我遇到了与No matching global declaration available for the validation root 类似的问题,但它并不能帮助我解决验证 XML 的问题。 在 php.net 的 cmets 中,我读到根元素的子元素也需要命名空间之类的。我尝试了变化,但它不能解决问题也不能改变消息。有谁知道怎么回事?

libxml Version => 2.7.6
libxml
libxml2 Version => 2.7.6
libxslt compiled against libxml Version => 2.7.6

PHP:

print_r($xml->schemaValidate('customer.xsd'));

错误:

PHP Warning:  DOMDocument::schemaValidate():
Element '{http://xxx.de/ecom-customer}customerExport':
No matching global declaration available for the validation root.

XML 开头:

<?xml version="1.0" encoding="UTF-8"?>
<xxx:customerExport xmlns:xxx="http://xxx.de/ecom-customer">
  <datasource>PROD</datasource>
...

XSD 部分:

<?xml version="1.0" encoding="UTF-8"?>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xxx="http://xxx.de/ecom-customer"
targetNamespace="http://xxx.de/ecom-customer"
jxb:version="2.0">

<xsd:element name="customerExport" type="xxx:customerExport"
    xmlns="xxx">
    <xsd:annotation>
        <xsd:appinfo>
            <jxb:class name="CustomerExportRoot" />
        </xsd:appinfo>
    </xsd:annotation>
</xsd:element>

【问题讨论】:

  • 您没有在 XSD 中定义命名空间 xxx/ecom-customer
  • 感谢您的反馈,将调查丢失的命名空间。

标签: php xml libxml2 xsd-validation


【解决方案1】:

您的架构文档应指定您为命名空间http://xxx/ecom-customer 声明元素(和其他内容)。在根元素上使用targetNamespace 属性。

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           elementFormDefault="qualified"
           targetNamespace="..."
>

  ...
  <xs:element name="customerExport">...</xs:element>
  ...
</xs:schema>

事实上,您的架构声明了一个扩展名为 {}customerExport 的元素,而不是扩展名为 {http://xxx/ecom-customer}customerExport 的元素。

【讨论】:

  • 我现在有一个更新的 XSD,其中包含 targetNamespace,其名称与我在 XML 中的命名空间相同,但我仍然遇到同样的错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-07
  • 2013-10-30
  • 1970-01-01
  • 2011-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多