0

我的示例的架构

<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="sss@sss.si"/>
<Professors id="2" name="fff" surname="ff" code="15446" email="ff@ff.si"/>

然后稍后我会使用 id 中的数字 1

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

我如何创建架构?

4

1 回答 1

1

如果“Professor”元素没有属性,它可以定义为:

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

它不需要具有内部属性。要将 Professor 元素的值限制为已定义的教授之一,您需要使用 key 和 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"/>
于 2013-05-30T18:43:27.493 回答