2013-05-30 136 views
0

架構限制了我的xampleXML與複雜類型

<xsd:element name="Subject" minOccurs="1" maxOccurs="1"> 
<xsd:annotation> 
    <xsd:documentation>Name of the subject. Values are: Vaje, Kolokvij, Predavanje, Izpit</xsd:documentation> 
</xsd:annotation> 
<xsd:simpleType> 
    <xsd:restriction base="xsd:string"> 
     <xsd:enumeration value="Vaje"/> 
     <xsd:enumeration value="Kolokvik"/> 
     <xsd:enumeration value="Predavanje"/> 
     <xsd:enumeration value="Izpit"/> 
    </xsd:restriction> 
</xsd:simpleType> 
</xsd:element> 

<xsd:element name="Professor" minOccurs="1" maxOccurs="1"> 
<xsd:annotation> 
<xsd:documentation>Name of the professors</xsd:documentation> 
</xsd:annotation> 
<xsd:complexType> 
<xsd:attribute name="prof" type="Professors"/> 
</xsd:complexType> 
</xsd:element> 

,我也有教授作爲限制,你不能插入別的

<xsd:element name="Professors"> 
<xsd:complexType> 
<xsd:attribute name="id"/> 
<xsd:attribute name="name"/> 
<xsd:attribute name="surname"/> 
<xsd:attribute name="code"/> 
<xsd:attribute name="email"/> 
</xsd:complexType> 
</xsd:element> 

,但我總是在這裏<xsd:attribute name="prof" type="Professors"/>這個錯誤

'Professors' must refer to an existing simple or complex type. 

我想要什麼? XML是這樣的:

<Professors id="1" name="sss" surname="sss" code="15426" email="[email protected]"/> 
<Professors id="2" name="fff" surname="ff" code="15446" email="[email protected]"/> 

,然後在以後的我笏使用的是1號從ID

<Subject>vaje</Subject> 
<Professor>1</Professor> 

如何創建模式?

回答

1

如果「教授」元素沒有屬性可以定義爲:

<xsd:element name="Professor" type="xsd:int"/> 

它並不需要有一個內在的屬性。要將教授元素的價值限制爲定義的教授之一,您需要使用密鑰和keyref:

<!-- The root element of the instance document --> 
<xsd:element name="Root"> 
    <xsd:complexType> 
     <!-- Subject ref and definition omitted for brevity --> 
     <xsd:element ref="Professors" maxOccurs="unbounded"/> 
     <xsd:element ref="Professor" maxOccurs="unbounded"/> 
    </xsd:complexType> 
    <xsd:key name="ProfessorId"> 
     <xsd:selector xpath="Professors"/> 
     <xsd:field xpath="@id"/> 
    </xsd:key> 
    <xsd:keyref name="ProfessorIdRef" refer="ProfessorId"> 
     <xsd:selector xpath="Professor"/> 
     <xsd:field xpath="text()"/> 
    </xsd:keyref> 
</xsd:element> 

<xsd:element name="Professors"> 
    <xsd:complexType> 
     <xsd:attribute name="id"/> 
     <xsd:attribute name="name"/> 
     <xsd:attribute name="surname"/> 
     <xsd:attribute name="code"/> 
     <xsd:attribute name="email"/> 
    </xsd:complexType> 
</xsd:element> 

<xsd:element name="Professor" type="xsd:string"/> 
+0

謝謝你的幫助 – senzacionale