W3C home > Mailing lists > Public > xmlschema-dev@w3.org > June 2007

Re: "Overriding" Attribute Declarations

From: Henry S. Thompson <ht@inf.ed.ac.uk>
Date: Tue, 12 Jun 2007 10:10:05 +0100
To: "Eliot Kimber" <ekimber@innodata-isogen.com>
Cc: <xmlschema-dev@w3c.org>
Message-ID: <f5blkep1qtu.fsf@hildegard.inf.ed.ac.uk>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Eliot Kimber writes:

> In XML DTDs, one can override the declaration of an attribute declared
> in an external declaration set by declaring the overriding version
> earlier, . . .

> I don't see an obvious way to do with with XSD using redefine.

Depends on the types of the attribute involved.  If the new type is a
restriction of the old, then this is straightforward:

baseAR.xsd:

<xs:schema>
 <xs:complexType name="b">
  <xs:attribute name="a" type="xs:string"/>
 </xs:complexType>
</xs:schema>

1AR.xsd:

<xs:schema>
 <xs:redefine schemaLocation="baseAR.xsd">  
 <xs:complexType name="b">
  <xs:complexContent>
   <xs:restriction base="b">
    <xs:attribute name="a" type="xs:token"/>
   </xs:restriction>
  </xs:complexContent>
 </xs:complexType>
 </xs:redefine>
</xs:schema>

If the new type is _not_ a restriction of the old type, _and_ it's
optional in the base, you can cheat.  This is against the spirit of
the REC, but in practice allowed (I believe):

First we get rid of the attribute:

2AR.xsd:

<xs:schema>
 <xs:redefine schemaLocation="baseAR.xsd">
 <xs:complexType name="b">
  <xs:complexContent>
   <xs:restriction base="b">
    <xs:attribute name="a" use="prohibited"/>
   </xs:restriction>
  </xs:complexContent>
 </xs:complexType>
 </xs:redefine>
</xs:schema>

Then we add it back with the desired type:

3AR.xsd:

<xs:schema>
 <xs:redefine schemaLocation="2AR.xsd">
 <xs:complexType name="b">
  <xs:complexContent>
   <xs:extension base="b">
    <xs:attribute name="a" type="xs:integer"/>
   </xs:extension>
  </xs:complexContent>
 </xs:complexType>
 </xs:redefine>
</xs:schema>

If this helps, hold your nose and go for it!

ht
- -- 
 Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
                     Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
            Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk
                   URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFGbmLtkjnJixAXWBoRAhgDAJ42zqyJXnxDDd563PERQF+OzuLYWwCdFHef
oObEhzbTgejT4ykMLo+a2fs=
=BG5E
-----END PGP SIGNATURE-----
Received on Tuesday, 12 June 2007 09:10:23 GMT

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