问题
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