2012-01-18 54 views
3

這是my.xsd模式:我的XML模式有什麼問題?

<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' 
    xmlns:p='some-namespace' targetNamespace='some-namespace'> 
    <xs:element name='root' type='p:main'/> 
    <xs:complexType name='main'> 
    <xs:sequence> 
     <xs:element name='alpha' type='xs:string' /> 
    </xs:sequence> 
    </xs:complexType> 
</xs:schema> 

這是我驗證針對它的XML文檔:

<root xmlns='some-namespace' 
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
    xsi:schemaLocation='some-namespace my.xsd'> 
    <alpha>xxx</alpha> 
</root> 

SAX解析器說:

"Invalid content was found starting with element 'alpha'. One of 
'{alpha}' is expected." 

有什麼不對?

+1

命名空間...... – bmargulies 2012-01-18 18:47:20

回答

4

你必須在你的模式定義添加

elementFormDefault="qualified" 

。不使用相對命名空間也是一個好主意,即使用類似這樣的:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:p="http://some-namespace" targetNamespace="http://some-namespace" 
elementFormDefault="qualified"> 
+0

你是對的,非常感謝! – yegor256 2012-01-18 18:54:19