2013-11-27 119 views
0

我遇到類似於No matching global declaration available for the validation root的問題,但它無法幫助我解決驗證XML問題。 在php.net的評論中,我讀過根元素的子元素也需要一個命名空間。我嘗試過變體,但它不會解決問題,也不會更改消息。有誰知道什麼是錯的?無法通過XSD驗證

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> 
+1

您沒有在XSD中定義名稱空間http:// xxx/ecom-customer。 – ThW

+0

感謝您的反饋,將調查缺少的名稱空間。 – DanFromGermany

回答

2

您的模式文檔應指定您正在聲明命名空間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

+0

我有一個更新的XSD現在包含'targetNamespace',其名稱與我的XML名稱空間相同,我仍然得到相同的錯誤。 – DanFromGermany

+0

就是這樣,謝謝你 – DanFromGermany