- From: Udo Ende <u.ende@mid.de>
- Date: Thu, 15 Sep 2005 10:25:23 +0200
- To: <xmlschema-dev@w3.org>
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 08:25:32 UTC