XML 架构:扩展 xsd:choice 以便创建选择的联合(不是序列) [英] XML Schema: Extend xsd:choice so that union (not sequence) of choices is created

查看:12
本文介绍了XML 架构:扩展 xsd:choice 以便创建选择的联合(不是序列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 XML 架构

I have the following XML Schema

<xsd:complexType name="SimpleThing">
    <xsd:choice maxOccurs="unbounded">
        <xsd:group ref="simpleContent" />
    </xsd:choice>
</xsd:complexType>

<xsd:complexType name="ExtendedThing">
    <xsd:complexContent>
        <xsd:extension base="SimpleThing">
            <xsd:choice maxOccurs="unbounded">
                <xsd:element name="qux" />
            </xsd:choice>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

<xsd:group name="simpleContent">
    <xsd:choice>
        <xsd:element name="foo" />
        <xsd:element name="bar" />
    </xsd:choice>
</xsd:group>

<xsd:group name="extendedContent">
    <xsd:choice>
        <xsd:group ref="simpleContent" />
        <xsd:element name="qux" />
    </xsd:choice>
</xsd:group>

<xsd:element name="root" type="ExtendedThing" />

我希望 ExtendedThing 类型以任意顺序包含 foobarqux.但是对于这个模式,qux 必须在 foobar 之后,因为一个序列,而不是选择的联合是从超类型和子类型的选择.

I would like the type ExtendedThing to contain foo, bar and qux in arbitrary order. But with this schema, qux must come after foo and bar because a sequence, not a union of the choices is created from the choice of the supertype and the choice of the subtype.

替代方案,用

<xsd:complexType name="ExtendedThing">
    <xsd:complexContent>
        <xsd:extension base="SimpleThing">
            <xsd:group ref="extendedContent" />
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

也不起作用,因为 独特的粒子属性违反了约束.

doesn't work either, because the Unique Particle Attribution constraint is violated.

是否有解决此问题的方法,或者是否无法在 XML Schema 中创建一种类型,该类型是另一种类型的扩展,使得新类型的内容是作为超集的一组元素(以任何顺序)超类型的内容?

Is there any solution to this problem or is it impossible to create a type in XML Schema that is an extension of another type such that the content of the new type is a set of elements (in any order) that is a superset of the content of the supertype?

推荐答案

由于实际原因,这是不可能的.超类型的内容模型必须始终完整地出现在子类型的内容模型之前.它有助于保持验证器的快速实现.

This is not possible, for practical reasons. The content model of a super-type must always come in entirety before the content model of the sub-type. It helps to keep the implementation of validators fast.

这篇关于XML 架构:扩展 xsd:choice 以便创建选择的联合(不是序列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆