0

異なるタイプのエントリで構成できる選択範囲の複合タイプを定義しようとしていますが、属性「multiselect」を持つことができるのは1つのエントリのみです。

これが私が試したことです:

<element name="selection" minOccurs="0" maxOccurs="unbounded">
  <complexType>
    <sequence>
      <element name="name" type="string" />
      <element name="source">
        <complexType>
          <choice>
            <element name="item" minOccurs="1" maxOccurs="unbounded" type="string" />
            <element name="path" type="string" minOccurs="1" maxOccurs="1" />
          </choice>
        </complexType>  
      </element>
    </sequence>
    <attribute name="multiselection" type="boolean" minOccurs="1" maxOccurs="1" />
  </complexType>
</element>

その結果、ソースが「item」タイプであるか「path」タイプであるかは問題ではない、「selection」の要素がさらに存在する可能性があります。ただし、属性multiselection=trueを持つことができるのは「selection」要素の1つだけです。

しかし、属性のmin-/maxOccuresはないようです。どうすればこれを回避できますか?

どうも

4

1 に答える 1

3

まず、min / maxOccursはパーティクル(ローカル要素、要素参照、グループ参照、シーケンス、選択)用に予約されています。属性の発生は、によって制御されます

use =(オプション|禁止|必須) -デフォルト値はオプションです

要素のセットの中でそれをさらに制限するために、trueの論理値(1またはリテラルのいずれかtrue)で指定された属性を持つことができるのは1つだけです。これはXSD1.0だけでは実行できないことです。XSDの上でSchematronを使用できます。

または、XSD1.1でこれを簡単に実現できます。

<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module (http://www.paschidev.com) -->
<xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="sample">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="selection" minOccurs="0" maxOccurs="unbounded">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="name" type="xsd:string"/>
                            <xsd:element name="source">
                                <xsd:complexType>
                                    <xsd:choice>
                                        <xsd:element name="item" minOccurs="1" maxOccurs="unbounded" type="xsd:string"/>
                                        <xsd:element name="path" type="xsd:string" minOccurs="1" maxOccurs="1"/>
                                    </xsd:choice>
                                </xsd:complexType>
                            </xsd:element>
                        </xsd:sequence>
                        <xsd:attribute name="multiselection" type="xsd:boolean" use="required"/>                        
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
            <xsd:assert test="count(selection[@multiselection=true()])=1"/>         
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

これらの線に沿った何か(falseまたは両方trueの両方が検証に失敗します):

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<sample xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <selection multiselection="false">
        <name>name1</name>
        <source>
            <item>item1</item>
            <item>item1</item>
        </source>
    </selection>
    <selection multiselection="false">
        <name>name1</name>
        <source>
            <item>item1</item>
            <item>item1</item>
        </source>
    </selection>
</sample>


cvc-assertion.3.13.4.1: Assertion evaluation ('count(selection[@multiselection=true()])=1') for element 'sample' with type '#anonymous' did not succeed. 

それらの1つを作成すると、true検証が成功するはずです。

于 2013-03-11T14:10:48.017 に答える