2016-08-02 63 views
1

我正在創建一個模式,但我被困在我的根元素附近,將其定義爲一個複雜類型,它具有子元素,屬性,對這些屬性的限制xsd:複雜類型與兒童,屬性和限制

這是我到目前爲止已經試過....(百葉簾格式)

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<xsd:element name="foos"> 
    <xsd:complexType> 
     <xsd:sequence> 
      <xsd:element name="foo" type="FooType" minOccurs="1" maxOccurs="unbounded"/> 
     </xsd:sequence>   
    </xsd:complexType> 
</xsd:element> 
<xsd:complexType name="FooType"> 
    <xsd:attribute name="exchangeType" type="xsd:string" use="required"> 
     <xsd:simpleType> 
      <xsd:restriction base="xsd:string"> 
       <xsd:enumeration value="S" /> 
       <xsd:enumeration value="T" /> 
      </xsd:restriction> 
     </xsd:simpleType> 
    </xsd:attribute> 
    <xsd:sequence> 
     <xsd:element name="thing1" type="Thing1Type" /> 
     <xsd:element name="thing2" type="Thing2Type" /> 
    </xsd:sequence> 
</xsd:complexType> 
</xsd:schema> 

我一直無法找到一個方法,將這個屬性和它的限制

任何思想S'

回答

1

兩個主要更正:

  1. xsd:attribute聲明不能同時擁有本地 xsd:simpleType@type屬性;刪除@type 屬性。
  2. xsd:attribute聲明不能出現在xsd:sequence之前; 之後移動它。

XSD與應用改正:

這XSD具有上述改正,並將應用於其他一些小的修改,現在是有效的:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <xsd:element name="foos"> 
    <xsd:complexType> 
     <xsd:sequence> 
     <xsd:element name="foo" type="FooType" 
        minOccurs="1" maxOccurs="unbounded"/> 
     </xsd:sequence>   
    </xsd:complexType> 
    </xsd:element> 
    <xsd:complexType name="FooType"> 
    <xsd:sequence> 
     <xsd:element name="thing1" type="Thing1Type" /> 
     <xsd:element name="thing2" type="Thing2Type" /> 
    </xsd:sequence> 
    <xsd:attribute name="exchangeType" use="required"> 
     <xsd:simpleType> 
     <xsd:restriction base="xsd:string"> 
      <xsd:enumeration value="S" /> 
      <xsd:enumeration value="T" /> 
     </xsd:restriction> 
     </xsd:simpleType> 
    </xsd:attribute> 
    </xsd:complexType> 
    <xsd:complexType name="Thing1Type"/> 
    <xsd:complexType name="Thing2Type"/> 
</xsd:schema> 
+0

謝謝,@kjhughes,這使得很多更有意義,並且是我需要的關於如何解決這個問題的清晰度 – kmancusi