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

Re: Overriding of a fixed value

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 10 Dec 2001 12:02:00 +0000
Message-ID: <7893530009.20011210120200@jenitennison.com>
To: Maikel Jansen <maikel.jansen@asml.com>
CC: xmlschema-dev@w3.org
Hi Maikel,

> I have a question about overriding fixed values.
>
> Consider the following complex type definition:
>
> <xs:complexType name="type0">
>   <xs:simpleContent>
>     <xs:extension base="int"/>
>   </xs:simpleContent>
>   <xs:attribute name="description" fixed="a description"/>
> </xs:complexType>

That isn't a legal complex type definition. The xs:attribute should be
within the xs:extension element, giving:

<xs:complexType name="type0">
  <xs:simpleContent>
    <xs:extension base="int">
      <xs:attribute name="description" fixed="a description" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

> Now, I want to express a type called type1 in an XML schema, such
> that type1 is an inheritance type of type0 and type1 overrides the
> (fixed) value of the attribute 'desc' of type0.

You cannot derive this type by restriction, as you cannot change the
fixed value constraint of the attribute if you derive by restriction.
I *think* that you can derive it by extension (I don't see anything
banning it in the Rec), as follows:

<xs:complexType name="type1">
  <xs:simpleContent>
    <xs:extension base="type0">
      <xs:attribute name="description" fixed="another description" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

But I think that you would get a cleaner hierarchy if you had a
general type with the (unfixed) description attribute:

<xs:complexType name="type">
  <xs:simpleContent>
    <xs:extension base="int">
      <xs:attribute name="description" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

And then derive the type0 and type1 from that type by restriction:

<xs:complexType name="type0">
  <xs:simpleContent>
    <xs:restriction base="type">
      <xs:attribute name="description" fixed="a description" />
    </xs:restriction>
  </xs:simpleContent>
</xs:complexType>

<xs:complexType name="type1">
  <xs:simpleContent>
    <xs:restriction base="type">
      <xs:attribute name="description" fixed="another description" />
    </xs:restriction>
  </xs:simpleContent>
</xs:complexType>

> However, this seems not to be correct because the following XML
> document that contains an element ('x') of type1 is not a correct
> instance:
>
> <x>
>   3
> </x> <-- unexpected character literal

It's hard to tell, but it looks as though that might be a
well-formedness error in the XML document. Check that it's well-formed
first, and then try validating against the schema. Also, make sure
that the schema is valid itself before you try validating the
instance.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Monday, 10 December 2001 07:02:02 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:25 GMT