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

Re: Redeclaring attribute in derived type

From: Jeni Tennison <jeni@jenitennison.com>
Date: Thu, 20 Dec 2001 15:36:46 +0000
Message-ID: <7113301937.20011220153646@jenitennison.com>
To: Jesse McCarthy <mccarthy36@earthlink.net>
CC: xmlschema-dev@w3.org
Hi Jesse,

> Can I redeclare an attribute when deriving a complexType? For
> example, if I want to create a generic type that specifies a minimal
> content model and one or more attributes and I want to derive other
> types from that, adding to the content model. and restricting the
> value of an attribute of the base type by setting a fixed or default
> value or restricting the value, etc. e.g.

If you want to both *extend* a type (adding to the content model) and
*restrict* a type (limiting attribute values), then you need to do it
in two steps - one a restriction and one an extension. You can do it
either way round, but since restrictions require you to specify the
full content model, it's easiest to do it first (on the shorter
content model):

<xs:complexType name="BaseType">
    <xs:element ref="JMM:someElementABC" />
  <xs:attribute name="id" type="xsd:ID" />

<xs:complexType name="RestrictedType">
    <xs:restriction base="JMM:BaseType">
        <xs:element ref="JMM:someElementABC" />
      <xs:attribute name="id" type="xs:ID" fixed="Derived" />

<xs:complexType name="ExtendedType">
    <xs:extension base="JMM:RestrictedType">
        <xs:element ref="JMM:someElementXYZ" />

By the way, this schema isn't valid because you can't specify a fixed
or default value on an attribute whose type is or is derived from
xs:ID (from Schema Component Constraint: Attribute Declaration
Properties Correct, clause 3). I kept it like that simply because that
was how you had it in your example.



Jeni Tennison
Received on Thursday, 20 December 2001 11:08:09 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:14:56 UTC