Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xml

xsd

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>
like image 758
Bharat Jangir Avatar asked Feb 24 '15 15:02

Bharat Jangir


People also ask

What is the purpose of XSD?

The XML Schema definition language (XSD) enables you to define the structure and data types for XML documents. An XML Schema defines the elements, attributes, and data types that conform to the World Wide Web Consortium (W3C) XML Schema Part 1: Structures Recommendation for the XML Schema Definition Language.

Why XSD is used in XML?

XSD Example The purpose of an XML Schema is to define the legal building blocks of an XML document: the elements and attributes that can appear in a document. the number of (and order of) child elements.

What is Union in schema?

Definition and Usage The union element defines a simple type as a collection (union) of values from specified simple data types.

What is an XSD schema?

What is XML Schema Definition (XSD)? XML Schema Definition or XSD is a recommendation by the World Wide Web Consortium (W3C) to describe and validate the structure and content of an XML document. It is primarily used to define the elements, attributes and data types the document can contain.


1 Answers

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}.

like image 92
kjhughes Avatar answered Nov 15 '22 20:11

kjhughes