is it possible in XML Schema to define the same element with several different definitions depending on one attribute.
As Example:
<xsd:element name="Element">
<xsd:complexType>
<xsd:sequence>
<xsd:attribute name="type" fixed="type1"/>
<xsd:seqeuence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Element">
<xsd:complexType>
<xsd:sequence>
<xsd:attribute name="type" fixed="type2"/>
<xsd:attribute name="value" type="xsd:integer"/>
<xsd:seqeuence>
</xsd:complexType>
</xsd:element>
<xsd:element name="RootElement">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="Element"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Or is there any other way to solve this problem.
It is important that both definitions are named “Element”, because I have an application needing that both elements are named the same way. But there is a second application that needs the additional information for type2.
Consider removing the
typeattribute and just defining two childnodes with the different structures you wish.This way you can have
and
in the same document.
Try this in the DTD section for
Element:or rather this if only one is ever allowed under
ElementandElementis not allowed to be empty:You can read more on about DTD element operators.