2012-04-27 4 views

答えて

3

ルースmaxOccurs="3"と何を得たことは、 "選択した少なくとも一つ"、ノー繰り返しです。

パーティクルの場合、デフォルトはです。各オプション粒子自体が必須である必須選択肢は、あなたの答えです。

更新:あなたのコメントに基づいて、あなたが説明した粒子の順序付けられた組み合わせであれば、これはXSD仕様で得られる最高のものです。

<?xml version="1.0" encoding="utf-8" ?> 
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:element name="root"> 
     <xsd:complexType> 
      <xsd:choice> 
       <xsd:sequence> 
        <xsd:element ref="c1"/> 
        <xsd:element ref="c2" minOccurs="0"/> 
        <xsd:element ref="c3" minOccurs="0"/> 
       </xsd:sequence> 
       <xsd:sequence> 
        <xsd:element ref="c2"/> 
        <xsd:element ref="c3" minOccurs="0"/> 
       </xsd:sequence> 
       <xsd:element ref="c3"/> 
      </xsd:choice> 
     </xsd:complexType> 
    </xsd:element> 
    <xsd:element name="c1" type="xsd:string"/> 
    <xsd:element name="c2" type="xsd:string"/> 
    <xsd:element name="c3" type="xsd:string"/> 
</xsd:schema> 

これは既に大変です。より多くのパーティクルや順序付けられていない組み合わせを探している場合は、モデルをこのようなものに変更します(これらはXSD 1.0の動作上の制限です。すべてがXPath構文の制限と関係しています)。セレクタ/フィールド)。

<?xml version="1.0" encoding="utf-8" ?> 
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    <xsd:element name="root"> 
     <xsd:complexType> 
      <xsd:sequence> 
       <xsd:element ref="c" maxOccurs="unbounded"/> 
      </xsd:sequence> 
     </xsd:complexType> 
     <xsd:key name="pk"> 
      <xsd:selector xpath="*"/> 
      <xsd:field xpath="@code"/> 
     </xsd:key> 
    </xsd:element> 
    <xsd:element name="c" type="TC" abstract="true"/> 
    <xsd:element name="c1" type="TC1" substitutionGroup="c"/> 
    <xsd:element name="c2" type="TC2" substitutionGroup="c"/> 
    <xsd:element name="c3" type="TC3" substitutionGroup="c"/> 

    <xsd:complexType name="TC"> 
     <xsd:simpleContent> 
      <xsd:extension base="xsd:string"> 
       <xsd:attribute name="code" type="xsd:string"/> 
      </xsd:extension> 
     </xsd:simpleContent> 
    </xsd:complexType> 
    <xsd:complexType name="TC1"> 
     <xsd:simpleContent> 
      <xsd:restriction base="TC"> 
       <xsd:attribute name="code" type="xsd:string" fixed="c1"/> 
      </xsd:restriction> 
     </xsd:simpleContent> 
    </xsd:complexType> 
    <xsd:complexType name="TC2"> 
     <xsd:simpleContent> 
      <xsd:restriction base="TC"> 
       <xsd:attribute name="code" type="xsd:string" fixed="c2"/> 
      </xsd:restriction> 
     </xsd:simpleContent> 
    </xsd:complexType> 
    <xsd:complexType name="TC3"> 
     <xsd:simpleContent> 
      <xsd:restriction base="TC"> 
       <xsd:attribute name="code" type="xsd:string" fixed="c3"/> 
      </xsd:restriction> 
     </xsd:simpleContent> 
    </xsd:complexType> 
</xsd:schema> 

サンプルXMLは次のようになります

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) --> 
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd"> 
    <c1 code="c1">c11</c1> 
    <c2 code="c2">c21</c2> 
    <c3 code="c3">c21</c3> 
</root> 

またはこの:基本的に、あなたの要素がユニークないくつかのコンポーネント上でキーイングしている

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) --> 
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd"> 
    <c2 code="c2">c21</c2> 
    <c1 code="c1">c11</c1> 
</root> 

、それはの一部であるがタグ名とは対照的にデータ。繰り返しますが、面倒ですが、練習として、あなたにアイデアを与えるかもしれません。

+0

私がmaxOccursを取り除くと、私は '複数のものを選ぶことはできません。私が「リース1」を意味するのは、(c1)、(c1とc2、c3)、(c2とc3)などです。 –

関連する問題