开发者

XSD: xs:sequence & xs:choice combination for xs:extension elements?

My 开发者_JS百科question is about defining an XML schema that will validate the following sample XML:

<rules>
    <other>...</other>
    <bool>...</bool>
    <other>...</other>
    <string>...</string>
    <other>...</other>
</rules>

The order of the child nodes does not matter. The cardinality of the child nodes is 0..unbounded.

All the child elements of the rules node have a common base type, rule, like so:

<xs:complexType name="booleanRule">
    <xs:complexContent>
        <xs:extension base="rule">
            ...
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

<xs:complexType name="stringFilterRule">
    <xs:complexContent>
        <xs:extension base="filterRule">
            ...
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

My current attempt at defining the schema for the rules node is below. However,

  1. Can I nest xs:choice within xs:sequence? If, where do I specify the maxOccurs="unbounded" attribute?
  2. Is there a better way to do this, such as an xs:sequence which specifies only the base type of its child elements?

        <xs:element name="rules">
            <xs:complexType>
                <xs:sequence>
                    <xs:choice>
                        <xs:element name="bool" type="booleanRule" />
                        <xs:element name="string" type="stringRule" />
                        <xs:element name="other" type="someOtherRule" />
                    </xs:choice>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    


  1. Yes, you can. You can specify maxOccurs="unbounded" where it better suits you. You can put it on xs:choice, for instance (I think that's what you're asking).
  2. You can use substitution groups. See this schema for example. ogc:expression is an abstract base element which may be substituted by different concrete expressions (ogc:Add and so on).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜