W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2002

Re: attribute derivation

From: Rahul Srivastava <Rahul.Srivastava@Sun.COM>
Date: Mon, 21 Jan 2002 14:56:03 +0000 (Asia/Calcutta)
Message-Id: <200201210931.g0L9V6F01555@blr-root.India.Sun.COM>
To: xmlschema-dev@w3.org
Cc: xiaofeng.wang@ps.ge.com
> xiaofeng.wang@ps.ge.com wrote...
> 
> If an attribute is declared in the base type within the <complexType> tag,
> will it become an attribute of a derived type? For example:
> 
> <complexType name="base">
>    <sequence>
>       <element name ="E1" type="string"/>
>       <element name ="E1" type="string"/>
>    </sequence>
>    <attribute name = "A1" type="string"/>
> </complexType>
> 
> <complexType name="derived">
>    <complexContent>
>       <extension base="base">
>          <sequence>
>              <element name="E3" type="string"/>
>          </sequence>
>      </extension>
>    <complextContent>
> </complexType>
> 
> Will "A1" be an attribute of "derived"?

Yes.

> What is the general way to treat an attribute in a derivation case?

The derivation can be an extension or restriction of a base.

#: When the derived is an extension of the base then:
All the attribute uses defined in the base are inherited by the derived. If 
there is an attribute use in derived with same name and targetnamespace, then 
its an error. You cannot restrict an attribute use defined in base when you are 
using extension. Thus, any attribute use with use as prohibited is removed 
before inheriting the attributes from the base.

example:
<complexType name="base">
   <sequence>
      ...
   </sequence>
   <attribute name = "A1" type="string"/>
   <attribute name = "A2" type="string"/>
</complexType>

<complexType name="derived">
   <complexContent>
      <extension base="base">
         <attribute name = "A1" type="string" use="prohibited"/>
         <attribute name = "A2" type="string"/>
     </extension>
   <complextContent>
</complexType>

The derived inherits attribute A1 from base, but gives an error for the 
attribute A2 as both have same name and targetnamespace.

#: When derived is a restriction of the base then:
All the attribute uses defined in the base are inherited by the derived except 
for those which you have declared in derived with use as prohibited or with a 
use which is different from the use in base.

example:
<complexType name="base">
   <sequence>
      ...
   </sequence>
   <attribute name = "A1" type="string"/>
   <attribute name = "A2" type="string" use="required"/>
</complexType>

<complexType name="derived">
   <complexContent>
      <extension base="base">
         <attribute name = "A1" type="string" use="prohibited"/>
         <attribute name = "A2" type="string" use="optional"/>
     </extension>
   <complextContent>
</complexType>

The derived restricts attribute A1 as prohibited (as if not declared either in 
base or derived) and restricts attribute A2 by changing the use from required to 
optional.

Hope this helps.
	
Cheers,
Rahul.

> 
> Thanks a lot
> Xiaofeng
> 
> 	
> Xiaofeng Wang
> GE Network Solutions
> 1990 West NASA Blvd, Melbourne Florida, 32904
> Voice: (321)435-5458, Fax: (321)435-5652
> xiaofeng.wang@ps.ge.com
> 
Received on Monday, 21 January 2002 04:31:21 GMT

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