XSD:如何限制派生的复杂类型的枚举值? [英] XSD: How to restrict enumeration values of a derived complex type?

查看:151
本文介绍了XSD:如何限制派生的复杂类型的枚举值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出以下示例:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="Book" abstract="true">
        <xs:sequence>
            <xs:element name="titel" type="xs:string">
            </xs:element>
            <xs:element name="bookCode" type="BookEnum"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Lyric">
        <xs:complexContent>
            <xs:extension base="Book">
                <xs:sequence>
                    <xs:element name="author" type="xs:string">
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:simpleType name="BookEnum">
        <xs:restriction base="xs:int">
            <xs:enumeration value="Paperback"/>
            <xs:enumeration value="Hardcover"/>
            <xs:enumeration value="Liporello"/>
            <xs:enumeration value="None"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

歌词源自Book.我想将为complexType"Lyric"的BookEnum的可能值限制为"Paperback".

Lyric derives from Book. I would like to restrict the possible values of the BookEnum for the complexType "Lyric" to be "Paperback".

"None","Liporello"和"Hardcover"应不再是"Lyric"的有效值.可以在xsd中完成吗?

"None", "Liporello" and "Hardcover" should no longer be valid values for "Lyric". can this be done in xsd?

推荐答案

不是,很遗憾,您不能这样做.没有办法限制这样的枚举,并且同时扩展和限制复杂类型也将遇到麻烦.您可以 此处.

Nope, unfortunately you cannot do that. There is no way to restrict an enumeration like that, and you also would have trouble both extending and restricting a complex type at the same time. There is a good article what you can do with enumerations here.

也许可以考虑自下而上地工作:定义基本的书本类型,其中几乎没有内容;然后定义一个LyricType,它是基本类型和更多值的并集;在子类型中携带bookCode.这不是理想的选择,但是XSD并不总是与面向对象的语言保持一致.

Maybe consider working bottom-up instead: define a basic book type with almost nothing in it; then define a LyricType that is a union of the basic type and some more values; carry the bookCode in the sub-types. It's not ideal, but alas, XSD does not always align with object-oriented languages.

这篇关于XSD:如何限制派生的复杂类型的枚举值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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