What is purpose of xsd:union in XML Schema (XSD)?

99封情书 提交于 2019-12-23 09:37:29

问题


I am parsing XSD for some purpose but facing issues with some XSD nodes. What is the use of the union in XSD and why it is used.

Is it used to put some sort of restriction on XML? I am attaching union and simple type node.

Please explain why it is used ?

<xsd:simpleType name="PeriodExtendedEnum">
    <xsd:union memberTypes="PeriodEnum">
        <xsd:simpleType>
            <xsd:restriction base="xsd:token">
                <xsd:enumeration value="T" />
            </xsd:restriction>
        </xsd:simpleType>
    </xsd:union>
</xsd:simpleType>


<xsd:simpleType name="PeriodEnum">
    <xsd:restriction base="xsd:token">
        <xsd:enumeration value="D" />
        <xsd:enumeration value="W" />
        <xsd:enumeration value="M" />
        <xsd:enumeration value="Y" />
    </xsd:restriction>
</xsd:simpleType>

回答1:


The xsd:union element allows derivation of a new type consisting of the union in the set theoretical sense of the types of its memberTypes.

In your example, PeriodExtendedEnum is the union of PeriodEnum {D, W, M, Y} and {T}: That is, PeriodExtendedEnum would allow all of the values of its two memberTypes: {D, W, M, Y, T}.



来源:https://stackoverflow.com/questions/28699121/what-is-purpose-of-xsdunion-in-xml-schema-xsd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!