Re: Redeclaring attribute in derived type

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:sequence>
    <xs:element ref="JMM:someElementABC" />
  </xs:sequence>
  <xs:attribute name="id" type="xsd:ID" />
</xs:complexType>

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

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

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.

Cheers,

Jeni

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

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