2012-02-27 99 views
14

我對XML Schema完全陌生,並且試圖讓基礎知識失效。這是我的xml架構代碼(文件名:example1.xsd):xml架構驗證錯誤「前綴未綁定」

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

<xs:element name="school"> 
    <xs:complexType> 
    <xs:sequence> 
     <xs:element name="element1" type="xs:string"/> 
     <xs:element name="element2" type="xs:string"/> 
     <xs:element name="element3" type="xs:string"/> 
     <xs:element name="element4" type="xs:string"/> 
    </xs:sequence> 
    </xs:complexType> 
</xs:element> 

</xs:schema> 

這是XML文檔。

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

<sample:school xmlns="http://www.example.com" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="./example1.xsd"> 

     <element1>hello</element1> 
     <element2>hello</element2> 
     <element3>hello</element3> 
     <element4>hello</element4> 

</sample:school> 

在試圖驗證XML文件,我從NetBeans的一個錯誤,指出: 爲元素的前綴「樣品」,「樣品:學校」未綁定。 [9]

回答

16

在你的XML,你要麼需要:

一個。從sample:school

卸下sample:前綴。更改xmlns="http://www.example.com"xmlns:sample="http://www.example.com"sample:添加前綴其餘元件(<sample:element1><sample:element2>等)

10

當你得到這樣的錯誤,最簡單的方法是添加前綴聲明;在你的情況下,按模式,只需添加到您的根元素以下屬性:

xmlns:sample="http://www.example.com" 

而且,這是相當具有XML namespaces有關。

相關問題