Skip to main content



      Home
Home » Archived » XML Schema Definition (XSD) » One element -> multiple types ?
One element -> multiple types ? [message #68146] Mon, 15 May 2006 08:55 Go to next message
Eclipse UserFriend
Hiya,

I'm tackling a design issue here. The following bit of XML Schema should
help. Is there any way I can tell this schema that one element can be of
different types?

These types actually quite look like the same (i.e.: have the same child
type in common [ZZZ]) except for the set of attributes they are tied to.
Namely, AAA, BBB or CCC may have attributes in common.

<xsd:complexType name="myComplexType">
<xsd:sequence>
<xsd:element name="myElement" minOccurs="0" maxOccurs="unbounded"
type="AAA"/>
-- ideally type="AAA|BBB|CCC"
<!-- some elements -->
</xsd:sequence>
<!-- some attributes -->
</xsd:complexType>

<xsd:complexType name="AAA">
<xsd:sequence>
<xsd:element name="ZZZ" type="xsd:string"/>
</xsd:sequence>
<!-- some attributes -->
</xsd:complexType>

<xsd:complexType name="BBB">
<xsd:sequence>
<xsd:element name="ZZZ" type="xsd:string"/>
</xsd:sequence>
<!-- some attributes -->
</xsd:complexType>

<xsd:complexType name="CCC">
<xsd:sequence>
<xsd:element name="ZZZ" type="xsd:string"/>
</xsd:sequence>
<!-- some attributes -->
</xsd:complexType>
Re: One element -> multiple types ? [message #68161 is a reply to message #68146] Mon, 15 May 2006 09:20 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Guillaume,

You could design a common base type ABC, have each of AAA, BBB, CCC
extend it, and make myElement of type ABC. ABC could perhaps be an
abstract type, so instance documents will be forced to use xsi:type to
specify one of AAA, BBB, or CCC.


Guillaume Windels wrote:

> Hiya,
>
> I'm tackling a design issue here. The following bit of XML Schema
> should help. Is there any way I can tell this schema that one element
> can be of different types?
>
> These types actually quite look like the same (i.e.: have the same
> child type in common [ZZZ]) except for the set of attributes they are
> tied to. Namely, AAA, BBB or CCC may have attributes in common.
>
> <xsd:complexType name="myComplexType">
> <xsd:sequence>
> <xsd:element name="myElement" minOccurs="0" maxOccurs="unbounded"
> type="AAA"/>
> -- ideally type="AAA|BBB|CCC"
> <!-- some elements -->
> </xsd:sequence>
> <!-- some attributes -->
> </xsd:complexType>
>
> <xsd:complexType name="AAA">
> <xsd:sequence>
> <xsd:element name="ZZZ" type="xsd:string"/>
> </xsd:sequence>
> <!-- some attributes -->
> </xsd:complexType>
>
> <xsd:complexType name="BBB">
> <xsd:sequence>
> <xsd:element name="ZZZ" type="xsd:string"/>
> </xsd:sequence>
> <!-- some attributes -->
> </xsd:complexType>
>
> <xsd:complexType name="CCC">
> <xsd:sequence>
> <xsd:element name="ZZZ" type="xsd:string"/>
> </xsd:sequence>
> <!-- some attributes -->
> </xsd:complexType>
Re: One element -> multiple types ? [message #598095 is a reply to message #68146] Mon, 15 May 2006 09:20 Go to previous message
Eclipse UserFriend
Guillaume,

You could design a common base type ABC, have each of AAA, BBB, CCC
extend it, and make myElement of type ABC. ABC could perhaps be an
abstract type, so instance documents will be forced to use xsi:type to
specify one of AAA, BBB, or CCC.


Guillaume Windels wrote:

> Hiya,
>
> I'm tackling a design issue here. The following bit of XML Schema
> should help. Is there any way I can tell this schema that one element
> can be of different types?
>
> These types actually quite look like the same (i.e.: have the same
> child type in common [ZZZ]) except for the set of attributes they are
> tied to. Namely, AAA, BBB or CCC may have attributes in common.
>
> <xsd:complexType name="myComplexType">
> <xsd:sequence>
> <xsd:element name="myElement" minOccurs="0" maxOccurs="unbounded"
> type="AAA"/>
> -- ideally type="AAA|BBB|CCC"
> <!-- some elements -->
> </xsd:sequence>
> <!-- some attributes -->
> </xsd:complexType>
>
> <xsd:complexType name="AAA">
> <xsd:sequence>
> <xsd:element name="ZZZ" type="xsd:string"/>
> </xsd:sequence>
> <!-- some attributes -->
> </xsd:complexType>
>
> <xsd:complexType name="BBB">
> <xsd:sequence>
> <xsd:element name="ZZZ" type="xsd:string"/>
> </xsd:sequence>
> <!-- some attributes -->
> </xsd:complexType>
>
> <xsd:complexType name="CCC">
> <xsd:sequence>
> <xsd:element name="ZZZ" type="xsd:string"/>
> </xsd:sequence>
> <!-- some attributes -->
> </xsd:complexType>
Previous Topic:One element -> multiple types ?
Next Topic:Analysis of XML Schema specific annotations, properties in Resource Impl.
Goto Forum:
  


Current Time: Fri Mar 14 06:26:09 EDT 2025

Powered by FUDForum. Page generated in 0.03872 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top