W3C home > Mailing lists > Public > xmlschema-dev@w3.org > June 2003

Re: Behaviour of <attribute> and <attributeGroup> in <restriction> element

From: Jeni Tennison <jeni@jenitennison.com>
Date: Tue, 17 Jun 2003 16:05:15 +0100
Message-ID: <100251724320.20030617160515@jenitennison.com>
To: "Hugh Wallis" <hugh_wallis@hyperion.com>
CC: xmlschema-dev@w3.org

Hi Hugh,

> Can anyone explain to me how <attribute> and <attributeGroup> work
> when they appear inside a <restriction> in a type defintion please?
>
> Are they used to restrict the permissible content of an attribute,
> the attributes in an attribute group?

Yes. For example, the "num" attribute could be restricted from being
any xs:integer to being an integer between 1 and 10.

> In particular can it be used to prohibit a specific attribute that
> was formerly permitted before the restriction was imposed (actually
> I hope this is NOT a possible use - the examples given in the primer
> seem to indicate I am right by virtue of the fact that they don't
> address this possibility)?

Yes, you can prohibit an attribute that was allowed in the base type
definition. You do this using the use="prohibited" attribute. For
example:

<xs:complexType name="person">
  <xs:attribute name="name" type="xs:token" />
  <xs:attribute name="age" type="xs:integer" />
</xs:complexType>

<xs:complexType name="ageless-person">
  <xs:complexContent>
    <xs:restriction base="person">
      <xs:attribute name="age" use="prohibited" />
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

Note that you can only prohibit optional attributes.

Other things that you can do on restriction are to make an attribute
required rather than optional, add a default value for the attribute,
or fix the attribute's value to the default value from the base type
definition.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Tuesday, 17 June 2003 11:05:29 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:15:11 UTC