2012-02-07 7 views
3

XMLスキーマタイプを指定する要素を含むスキーマを定義したいと思います。この質問は、XML Schema for schemasとこのquestionに関連している可能性があります。XMLスキーマ:タイプのタイプの定義

は、ここで私がこれまで持っているものです。

<xs:complexType name="metatype"> 
    <xs:sequence> 
     <xs:element name="datatype" type="datatype" minOccurs="0" maxOccurs="1"/> 
     <xs:element name="location" type="locationtype" minOccurs="0"maxOccurs="unbounded"/> 
     <xs:element name="alias" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> 
    </xs:sequence> 
    <xs:attribute name="id" type="xs:ID" use="required"/> 
    <xs:attribute name="editable" type="xs:boolean" default="false" use="optional"/> 
    <xs:attribute name="forcedvisible" type="xs:boolean" default="false" use="optional"/> 
</xs:complexType> 
データ型がある

<xs:complexType name="datatype"> 
    <xs:sequence> 
     <xs:element name="restriction"> 
     <xs:complexType> 
      <xs:sequence> 
      <xs:element name="enumeration"> 
       <xs:complexType> 
       <xs:attribute name="value" type="xs:string" use="required"/> 
       </xs:complexType> 
      </xs:element> 
      </xs:sequence> 
      <xs:attribute name="base" type="xs:string" use="required"/> 
      <!-- type xs:string is not accurate for XML Schema type --> 
     </xs:complexType> 
     </xs:element> 
    </xs:sequence> 
</xs:complexType> 

代わりのデータ型を宣言し、私はSchema for schemasまたは少なくともsimpleRestrictionTypelocalSimpleTypeを使用したいのですが、私のXMLスキーマエディタ(Visual Studio)は、これらのタイプを認識していないようです。私が参照する必要がある別のXMLスキーマ文書がありますか?

答えて

1

私はS4Sをインポートするスキーマとそれに定義された参照型を書くことができるはずだと思います。しかし、いくつかのツールが反対する可能性は全くあります。

変更したS4Sを処理したり、余分なコンポーネントをXSD名前空間に追加したりしないでください。スキーマ対応のツールは、S4Sのすべてを公理的なものとして扱い、これらのコンポーネントのビルトインの知識とは異なる定義でそれらを提示することで、無駄な混乱を引き起こす可能性があります。

1

XMLスキーマsimpleTypeの要素とそのサブタグを制限することを避けたいと思っています。xsdを使用するか、独自のパーサを作成したいですか?

制限の有無にかかわらずタイプを定義することができます。また、通常はxsを含む既知の名前空間の定義済みタイプにローカル制限を追加することもできます。

現地の制限は、例えば

(自分自身を繰り返しscroll down toパソコンへ転送)何度もそれ以上を使用する場合は、DRYのための新しいタイプを定義し、1つのトレードオフのために最適です

<xs:simpleType name="mySimpleTypeA"> 
    <xs:restriction base = "xs:string"> 
    <xs:enumeration value ="on"/> 
    <xs:enumeration value = "off"/> 
    </xs:restriction> 
</xs:simpleType> 

<xs:complexType name="myComplexTypeA> 
    <xs:sequence> 
    <xs:element name="someElementName"> 
     <xs:simpleType> 
     <xs:restriction base ="xs:string"> 
      <xs:minLength ="8"/> 
     </xs:restriction> 
     </xs:simpleType> 
    </xs:element> 
    </xs:sequence> 
    <xs:attribute name="someAttributeName" use="required" type="mySimpleTypeA"/> 
</xs:complexType> 

あなたの要素の制限を呼び出す
<xs:element name = "Fred" type ="myComplexTypeA"/> 

で、それ1にするつもりはないとして、あなたはそれらを使用することができます...

ああ私の頭の上からこれを守りませんでしたが、それは近いはずです。

関連する問題