RE: puzzling over use="prohibited"

Hi Jeni,

Thanks. I didn't realize that attributes do inherit through complex type
derivation. That fact provides the answer I was looking for.

Don

-----Original Message-----
From: Jeni Tennison [mailto:jeni@jenitennison.com]
Sent: Tuesday, April 02, 2002 10:12 AM
To: Don Smith
Cc: Schema
Subject: Re: puzzling over use="prohibited"


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:complexContent>
   <xs:extension base="xs:annotated">
    <xs:sequence>
     <xs:element name="simpleType" minOccurs="0" type="xs:localSimpleType"/>
    </xs:sequence>
    <xs:attributeGroup ref="xs:defRef"/>
    <xs:attribute name="type" type="xs:QName"/>
    <xs:attribute name="use" use="optional" default="optional">
     <xs:simpleType>
      <xs:restriction base="xs:NMTOKEN">
       <xs:enumeration value="prohibited"/>
       <xs:enumeration value="optional"/>
       <xs:enumeration value="required"/>
      </xs:restriction>
     </xs:simpleType>
    </xs:attribute>
    <xs:attribute name="default" type="xs:string"/>
    <xs:attribute name="fixed" type="xs:string"/>
    <xs:attribute name="form" type="xs:formChoice"/>
   </xs:extension>
  </xs:complexContent>
 </xs:complexType>

 <xs:complexType name="topLevelAttribute">
  <xs:complexContent>
   <xs:restriction base="xs:attribute">
    <xs:sequence>
     <xs:element ref="xs:annotation" minOccurs="0"/>
     <xs:element name="simpleType" minOccurs="0" type="xs:localSimpleType"/>
    </xs:sequence>
    <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"/>
   </xs:restriction>
  </xs:complexContent>
 </xs:complexType>

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".

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Tuesday, 2 April 2002 11:20:01 UTC