RE: A question on "Restriction"

> 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 UTC