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

Re: puzzling over use="prohibited"

From: Jeni Tennison <jeni@jenitennison.com>
Date: Tue, 2 Apr 2002 17:11:59 +0100
Message-ID: <5531117835.20020402171159@jenitennison.com>
To: "Don Smith" <donalds@isogen.com>
CC: "Schema" <xmlschema-dev@w3.org>
Hi Don,

> Is use="prohibited" simply a way to "turn off" an attribute
> declaration without deleting it?
> That's the only way I can imagine using it. Is there some other way
> or use case I'm missing?

You can use it like that, but it's intended to be used when you
restrict a type. There are several nice examples in the schema for XML
Schema, in fact. For example:

 <xs:complexType name="attribute">
   <xs:extension base="xs:annotated">
     <xs:element name="simpleType" minOccurs="0" type="xs:localSimpleType"/>
    <xs:attributeGroup ref="xs:defRef"/>
    <xs:attribute name="type" type="xs:QName"/>
    <xs:attribute name="use" use="optional" default="optional">
      <xs:restriction base="xs:NMTOKEN">
       <xs:enumeration value="prohibited"/>
       <xs:enumeration value="optional"/>
       <xs:enumeration value="required"/>
    <xs:attribute name="default" type="xs:string"/>
    <xs:attribute name="fixed" type="xs:string"/>
    <xs:attribute name="form" type="xs:formChoice"/>
 <xs:complexType name="topLevelAttribute">
   <xs:restriction base="xs:attribute">
     <xs:element ref="xs:annotation" minOccurs="0"/>
     <xs:element name="simpleType" minOccurs="0" type="xs:localSimpleType"/>
    <xs:attribute name="ref" use="prohibited"/>
    <xs:attribute name="form" use="prohibited"/>
    <xs:attribute name="use" use="prohibited"/>
    <xs:attribute name="name" use="required" type="xs:NCName"/>

By default when you derive a complex type from another complex type,
all the attributes on the base complex type are inherited by the
derived complex type. (This is different from how element content is
inherited, where you have to explicitly specify the content model of
the derived type.)

In the above example, the base type is the xs:attribute type, which
defines a number of attributes -- name, ref, type, use, default, fixed
and form. Top level attributes aren't allowed to have some of these
attributes, however -- they're not allowed to have ref, form or use
attributes. To stop these attributes from being inherited by the
xs:topLevelAttribute type (and hence permitted), they are prohibited
with use="prohibited".



Jeni Tennison
Received on Tuesday, 2 April 2002 11:12:01 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:56 UTC