Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Referencing similar lists through a complexType

From: "Udo Ende" <u.ende@---.-->
To: <xmlschema-dev@--.--->
Date: 9/15/2005 12:25:00 PM

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


From mike@s... Thu Sep 15 09:23:12 2005
Received: from maggie.w3.org ([193.51.208.68])
	by frink.w3.org with esmtp (Exim 4.50)
	id 1EFpxY-00017Q-F1
	for xmlschema-dev@l...; Thu, 15 Sep 2005 09:23:12 +0000
Received: from uk


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent