XML Schema: all, sequence & groups

前端 未结 1 2100
暗喜
暗喜 2020-12-22 12:56

I\'m writing an XML schema for the first time and I found some usefull tools to help me writing it.

Now I\'m in a strange situation. The schema I wrote is valid for s

相关标签:
1条回答
  • 2020-12-22 13:24

    The schema you have seems to be invalid according to the 1.0 version which states plainly here (Primer) that

    XML Schema stipulates that an all group must appear as the sole child at the top of a content model.

    Alternatively, try to read section 3.8.6 of the XML Schema Structures here. To your list I would add .NET's XSD processor, which in your case will complain as:

    The group ref to 'all' is not the root particle, or it is being used as an extension.

    With XSD 1.0 there is no solution that would give you what you want nicely and with a concised syntax unless you build a wrapper for e1 elements (below as e1s).

    <?xml version="1.0" encoding="utf-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:group name="test">
            <xsd:all>
                <xsd:element name="e1s" minOccurs="0">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="e1" maxOccurs="unbounded"/>
                        </xsd:sequence>
                    </xsd:complexType>
                </xsd:element>
                <xsd:element name="e2" minOccurs="0"/>
                <xsd:element name="e3" minOccurs="0"/>
                <xsd:element name="e4" minOccurs="0"/>
            </xsd:all>
        </xsd:group>
        <xsd:element name="e0">
            <xsd:complexType>
                <xsd:group ref="test"/>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema> 
    

    When it comes to e1 elements, they must be wrapped in e1s

    <e0>
        <e1s>
            <e1/>
            <e1/>
            <e1/>
            <e1/>
            <e1/>
        </e1s>
        <e2/>
    </e0>  
    

    or

    <e0>
        <e1s>
            <e1/>
        </e1s>
        <e2/>
        <e3/>
        <e4/>
    </e0>     
    

    Then it'll all validate...

    0 讨论(0)
提交回复
热议问题