W3C home > Mailing lists > Public > xmlschema-dev@w3.org > September 2005

RE: Referencing similar lists through a complexType

From: Michael Kay <mike@saxonica.com>
Date: Thu, 15 Sep 2005 10:22:51 +0100
To: "'Udo Ende'" <u.ende@mid.de>, <xmlschema-dev@w3.org>
Message-ID: <E1EFpxP-0000J2-W2@maggie.w3.org>

There's something wrong with a design that uses element names "OuterOne" and
"OuterTwo" and envisages extending this to "OuterThree" and "OuterFour". It
suggests that you're packing data into the element names, whereas they
should be used only to indicate the structure.

Replace <OuterOne ...> with <Outer level="1" ...> and your processing will
become much simpler.

Michael Kay
http://www.saxonica.com/

 

> -----Original Message-----
> From: xmlschema-dev-request@w3.org 
> [mailto:xmlschema-dev-request@w3.org] On Behalf Of Udo Ende
> Sent: 15 September 2005 09:25
> To: xmlschema-dev@w3.org
> Subject: Referencing similar lists through a complexType
> 
> 
> 
> Hi,
> 
> this xml data is valid due to the following schema:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Example xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>     <OuterOne id="Outer1">
>          <MiddleOne id="Middle1_1">
>             <Inner>8</Inner>
>         </MiddleOne>
>         <MiddleTwo id="Middle2_1">
>             <Inner>6</Inner>
>         </MiddleTwo>
>         <MiddleOne id="Middle1_2">
>             <Inner>3</Inner>
>         </MiddleOne>
>         <MiddleTwo id="Middle2_3">
>             <Inner>1</Inner>
>         </MiddleTwo>
>      </OuterOne>
>     <OuterTwo id="Outer2">
>         <MiddleTwo id="Middle2_2">
>             <Inner>0</Inner>
>         </MiddleTwo>
>          <MiddleOne id="Middle1_3">
>             <Inner>1</Inner>
>         </MiddleOne>
>         <MiddleOne id="Middle1_4">
>             <Inner>5</Inner>
>         </MiddleOne>
>      </OuterTwo>
> </Example>
> 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
>   <xs:element name="Example">
>     <xs:complexType>
>       <xs:sequence>
>         <xs:element ref="OuterOne"/>
>         <xs:element ref="OuterTwo"/>
>       </xs:sequence>
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="OuterOne">
>     <xs:complexType>
>       <xs:choice maxOccurs="unbounded">
>         <xs:element ref="MiddleOne"/>
>         <xs:element ref="MiddleTwo"/>
>       </xs:choice>
>       <xs:attribute name="id" use="required" type="xs:NCName"/>
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="OuterTwo">
>     <xs:complexType>
>       <xs:sequence>
>         <xs:element ref="MiddleTwo"/>
>         <xs:element maxOccurs="unbounded" ref="MiddleOne"/>
>       </xs:sequence>
>       <xs:attribute name="id" use="required" type="xs:NCName"/>
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="MiddleOne">
>     <xs:complexType>
>       <xs:complexContent>
>         <xs:extension base="Inner">
>           <xs:attribute name="id" use="required" type="xs:NCName"/>
>         </xs:extension>
>       </xs:complexContent>
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="MiddleTwo">
>     <xs:complexType>
>       <xs:complexContent>
>         <xs:extension base="Inner">
>           <xs:attribute name="id" use="required" type="xs:NCName"/>
>         </xs:extension>
>       </xs:complexContent>
>     </xs:complexType>
>   </xs:element>
>   <xs:complexType name="Inner">
>     <xs:sequence>
>       <xs:element ref="Inner"/>
>     </xs:sequence>
>   </xs:complexType>
>   <xs:element name="Inner" type="xs:integer"/>
> </xs:schema>
> 
> 
> Both "OuterOne" and "OuterTwo" do have "MiddleOne"s and 
> "MiddleTwo"s in it,
> therefore the schema references both complexTypes "MiddleOne" and
> "MiddleTwo". Assume there would be (much) more than only two 
> complexTypes,
> so each "Outer..." must reference all of these. Therefore the 
> schema gets
> bigger and bigger within each of the "Outer..." having the 
> same complexTypes
> referenced.
> Can I only reference ONE complexType inside of the "Outer..." 
> without having
> the need of another tag?
> 
> The following is a compromise, but with another tag called 
> "AnotherLevel":
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Example xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>     <OuterOne id="Outer1">
> 		<AnotherLevel>
> 			<MiddleOne id="Middle1_1">
> 				<Inner>8</Inner>
> 			</MiddleOne>
> 			<MiddleTwo id="Middle2_1">
> 				<Inner>6</Inner>
> 			</MiddleTwo>
> 			<MiddleOne id="Middle1_2">
> 				<Inner>3</Inner>
> 			</MiddleOne>
> 			<MiddleTwo id="Middle2_3">
> 				<Inner>1</Inner>
> 			</MiddleTwo>
> 		</AnotherLevel>
>     </OuterOne>
>     <OuterTwo id="Outer2">
> 		<AnotherLevel>
> 			<MiddleTwo id="Middle2_2">
> 				<Inner>0</Inner>
> 			</MiddleTwo>
> 			<MiddleOne id="Middle1_3">
> 				<Inner>1</Inner>
> 			</MiddleOne>
> 			<MiddleOne id="Middle1_4">
> 				<Inner>5</Inner>
> 			</MiddleOne>
> 		</AnotherLevel>
> 	</OuterTwo>
> </Example>
> 
> and the schema:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <xs:schema elementFormDefault="qualified"
> xmlns:xs="http://www.w3.org/2001/XMLSchema">
>   <xs:element name="Example">
>     <xs:complexType>
>       <xs:sequence>
>         <xs:element ref="OuterOne" />
>         <xs:element ref="OuterTwo" />
>       </xs:sequence>
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="OuterOne">
>     <xs:complexType>
>       <xs:choice maxOccurs="unbounded">
>         <xs:element ref="AnotherLevel" />
>       </xs:choice>
>       <xs:attribute name="id" type="xs:NCName" use="required" />
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="OuterTwo">
>     <xs:complexType>
>       <xs:choice maxOccurs="unbounded">
>         <xs:element ref="AnotherLevel" />
>       </xs:choice>
>       <xs:attribute name="id" type="xs:NCName" use="required" />
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="AnotherLevel">
>     <xs:complexType>
>       <xs:choice maxOccurs="unbounded">
>         <xs:element ref="MiddleOne" />
>         <xs:element ref="MiddleTwo" />
>       </xs:choice>
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="MiddleOne">
>     <xs:complexType>
>       <xs:complexContent mixed="false">
>         <xs:extension base="Inner">
>           <xs:attribute name="id" type="xs:NCName" use="required" />
>         </xs:extension>
>       </xs:complexContent>
>     </xs:complexType>
>   </xs:element>
>   <xs:element name="MiddleTwo">
>     <xs:complexType>
>       <xs:complexContent mixed="false">
>         <xs:extension base="Inner">
>           <xs:attribute name="id" type="xs:NCName" use="required" />
>         </xs:extension>
>       </xs:complexContent>
>     </xs:complexType>
>   </xs:element>
>   <xs:complexType name="Inner">
>     <xs:sequence>
>       <xs:element ref="Inner" />
>     </xs:sequence>
>   </xs:complexType>
>   <xs:element name="Inner" type="xs:integer" />
> </xs:schema>
> 
> 
> Can I do that without the need of the "AnotherLevel"-Tag???
> 
> Regards,
> Udo
> 
> 
> 
Received on Thursday, 15 September 2005 09:23:12 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:50 GMT