2016-08-02 69 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