2

私はこのXMLを持っています

<button onclick="alert('submit')" replace="append" forid="loginbutton" id="btnLogin" >Click Me</button>

そして、私はこのXSDを持っています

  <xs:element name="button" >
    <xs:complexType mixed="true">
                <xs:attribute name="forid" use="required" type="xs:string" />
                <xs:attribute name="onclick" use="required" />
                <xs:attribute name="id" use="optional" />
                <xs:attribute name="replace" use="required">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="modify" />
                            <xs:enumeration value="append" />
                        </xs:restriction>
                    </xs:simpleType>
                </xs:attribute>
    </xs:complexType>
  </xs:element>

ここで2つのことが欲しい

  1. ボタンのコンテンツ テキストは、すべての場合において必須である必要があります
  2. replace属性の値が「追加」の場合、属性idは必須になります
4

2 に答える 2

3

これをcomplex-type-with-simple-contentにすると、xs:enumerationを使用してテキストの許可された値を制限できます。複雑なタイプと混合コンテンツを作成する場合、テキストの内容を制限することはできません。ここでは、混合コンテンツではなく、単純なコンテンツが必要なようです(子要素はありません)。

XSD 1.0を使用して共制約(あるものの値が別の値に依存する)を定義することはできません-そのためにはXSD1.1が必要です。XSD 1.1のサポートは、現在SaxonとXercesでのみ利用可能です。

于 2011-03-17T08:33:55.040 に答える
1

私はなんとかそれを成し遂げることができました。よくわかりませんでした。基本的には試行錯誤しました。誰かがこれが何を意味するのか説明できれば、私は感謝するでしょう。

<xs:element name="button">
    <xs:complexType>
        <xs:simpleContent>
            <xs:restriction base="xs:anyType">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:minLength value="1" />

                    </xs:restriction>
                </xs:simpleType>
                <xs:attribute name="forid" use="required" type="xs:string" />
                <xs:attribute name="onclick" />
                <xs:attribute name="id" use="optional" />
                <xs:attribute name="type" use="required" />
                <xs:attribute name="replace" use="required">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="modify" />
                            <xs:enumeration value="append" />
                        </xs:restriction>
                    </xs:simpleType>
                </xs:attribute>

            </xs:restriction>
        </xs:simpleContent>
    </xs:complexType>
</xs:element>
于 2011-03-18T04:19:19.530 に答える