One element -> multiple types ? [message #68146] |
Mon, 15 May 2006 08:55  |
Eclipse User |
|
|
|
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  |
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  |
Eclipse User |
|
|
|
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>
|
|
|
Powered by
FUDForum. Page generated in 0.03872 seconds