2016-08-02 4 views
1

私はスキーマの作成に取り組んでいますが、子要素、属性、およびの属性を持つcomplexTypeとして定義すると、ルート要素の近くに詰まっていますxsd:complexType子、属性、制限付き

この は(ブラインド形式)

<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> 

私は

任意の考えを、この属性を組み込むための方法を見つけ、その制約問題を抱えてきた....私がこれまで試してみましたものです?

答えて

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

関連する問題