扩展 XSD 文件 [英] Extending XSD files

查看:24
本文介绍了扩展 XSD 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个枚举类型的 XSD 文件.我想创建一个扩展的"XSD 文件,它添加了一些额外的枚举,但其他方面的行为与主 XSD 一样.

I have an XSD file with an enumerated type. I'd like to create an "extended" XSD file, which adds some additional enumerations, but otherwise behaves just like the main XSD.

例如,主 XSD 文件包含以下内容:

For example, the main XSD file contains this:

<xsd:simpleType name="color">
    <xsd:restriction base="xsd:string">
        <xsd:enumeration value="red"></xsd:enumeration>
        <xsd:enumeration value="orange"></xsd:enumeration>
        <xsd:enumeration value="yellow"></xsd:enumeration>
    </xsd:restriction>
</xsd:simpleType>
...
<xsd:element name="myColor" type="color" />

我想象中的扩展 XSD 文件只会在颜色"类型中添加金色".现有的myColor"元素现在可以包含gold",如果它使用这个 XSD 而不是主要的.

My imaginary extended XSD file would simply add "gold" to the "color" type. The existing "myColor" element would now be able to contain "gold", if it used this XSD instead of the main one.

这可能吗?

推荐答案

这样的事情怎么样?

<!-- Your base enumeration -->
<xsd:simpleType name="color">
    <xsd:restriction base="xsd:string">
        <xsd:enumeration value="red"/>
        <xsd:enumeration value="orange"/>
        <xsd:enumeration value="yellow"/>
    </xsd:restriction>
</xsd:simpleType>

<!-- You extended enumeration -->
<xsd:simpleType name="colorEx">
    <xsd:restriction base="xsd:string">
        <xsd:enumeration value="gold"/>
    </xsd:restriction>
</xsd:simpleType>


<xsd:simpleType name="color_union">
     <xsd:union memberTypes="colorEx color"/>
</xsd:simpleType>

<xsd:element name="myColor" type="color_union"/>

这篇关于扩展 XSD 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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