Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » One element -> multiple types ?
One element -> multiple types ? [message #68146] Mon, 15 May 2006 08:55 Go to next message
Guillaume Windels is currently offline Guillaume Windels
Messages: 29
Registered: July 2009
Junior Member
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 User
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
Ed Merks is currently offline Ed Merks
Messages: 25750
Registered: July 2009
Senior Member
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: Thu Apr 24 01:55:11 EDT 2014

Powered by FUDForum. Page generated in 0.02297 seconds