W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2000

RE: A question on "Restriction"

From: David Valera <dvalera@pcl-hage.nl>
Date: Fri, 15 Dec 2000 10:06:36 +0100
To: "'Yimin Zhu'" <yzhu@citadon.com>, <xmlschema-dev@w3.org>
Message-ID: <D1F94D8C7C1FD111A5290020AF92B1B3B03A29@INTRASERVER>
> If I have a complextType A containing two sub elements B and C.
>
> <complexType name="A">
> 	<complexContent>
> 		<element name="B" type="string"/>
> 		<element name="C" type="string"/>
> 	</complexContent>
> </ComplexType>
>
> Now I wish to define an element E, which is inherited from A.
> Also, E can
> only have B in its content model. Can I do it by using restriction as
> following?

Actually no, because the declarations or facets in the definition of E must
be in a one-to-one relation with the type definition of A.

furthermore, members of E which is declared as a restriction of A, are
always members of A as well.

This means that you can do the following:

 <xsd:complexType name="A">
 	<xsd:complexContent>
 		<xsd:element name="B" type="string" minOccurs="0"/>
 		<xsd:element name="C" type="string"/>
 	</xsd:complexContent>
 </xsd:ComplexType>

 <xsd:element name="E">
   <xsd:complexType>
	<xsd:complexContent>
		<xsd:estriction base="A">
			<xsd:all>
				<xsd:element name="B" type="string"/>
		 		<xsd:element name="C" type="string"/>
			</xsd:all>
		</xsd:restriction>
	</xsd:complexContent>
   </xsd:complexType>
 </xsd:element>

What you are probably looking for is the use of extension instead of
restriction:

First declare the complextype for element E, and then extend it to declare
the type A. Something like:

<xsd:element name="E" type="EType">

<xsd:complexType name="EType">
  <xsd:sequence>
		<xsd:element name="B" type="string"/>
  </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="A">
  <xsd:complexContent>
   <xsd:extension base="EType">
    <xsd:sequence>
 		<xsd:element name="C" type="string"/>
    </xsd:sequence>
   </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>

I hope this helps.
Received on Friday, 15 December 2000 04:05:53 GMT

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