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

Re: Attribute uses of complexType complexContent restriction

From: Jeni Tennison <jeni@jenitennison.com>
Date: Thu, 13 Dec 2001 09:50:15 +0000
Message-ID: <264815800.20011213095015@jenitennison.com>
To: "Lemmin, Harald" <Harald.Lemmin@softwareag.com>
CC: xmlschema-dev@w3.org
Hi Harald,

> I'm confused about the attribute uses of complexType complexContent
> restriction:
> The primer states in "4.4 Deriving Complex Types by Restriction":
> "Notice that types derived by restriction must repeat all the components of
> the base type definition that are to be included in the derived type:"
> My question: Does this hold true for the attribute declarations, too?

No, it doesn't apply to attributes, just to elements.

The attribute uses from the base type are inherited by the restricted
type whether you specify them in the restricted type or not. You can
*prevent* an attribute use from being inherited by the restricted type
by specifying that attribute with use="prohibited" in the restricted
type, which prevents it from being added to the attribute uses for the
restricted type.

> Example:
> <xs:complexType name="baseType">
>  <xs:attribute name = "att1" type = "xs:string" use = "optional"/>
>  <xs:attribute name = "att2" type = "xs:string" use = "optional"/>
>  <xs:attribute name = "att3" type = "xs:string" use = "optional"/>
>  <xs:attribute name = "att4" type = "xs:string" use = "optional"/>
> </xs:complexType>
> <xs:complexType name="restrictedType">
>  <xs:complexContent>
>   <xs:restriction base = "target:baseType">
>    <xs:attribute name = "att1" type = "xs:string" use = "required"/>
>    <xs:attribute name = "att2" type = "xs:string" use = "prohibited"/>
>    <xs:attribute name = "att3" type = "xs:string" use = "optional"/>
>   </xs:restriction>
>  </xs:complexContent>
> </xs:complexType>
> That means:
> att1 -> restricted by putting from optional to required.


> att2 -> restricted by putting from optional to prohibited.

Yes, such that elements of the restrictedType cannot have the att2

> att3 -> mentioned again, because it should be still there.

You can mention it again as you have if you want, but you don't have
to. The attribute declaration you've included in the restrictedType
could be safely omitted if you wanted att3 to be exactly the same.

> att4 -> not mentioned, because "restrictedType" should not have this
> attribute. 

That's not the effect of leaving out att4. To stop att4 being allowed
in the restrictedType, you have to do what you did for att2, and make
use="prohibited". As you've left it out, this attribute will be
inherited from the base type.

I hope that clears things up for you,


Jeni Tennison
Received on Thursday, 13 December 2001 04:50:16 GMT

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