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>
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.
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.
Definition and Usage The union element defines a simple type as a collection (union) of values from specified simple data types.
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.
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
}.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With