W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2002

Re: Derivation by restriction from <any>

From: Jeni Tennison <jeni@jenitennison.com>
Date: Tue, 12 Mar 2002 11:10:07 +0000
Message-ID: <107609629921.20020312111007@jenitennison.com>
To: Simon.Cox@csiro.au
CC: xmlschema-dev@w3.org, dareo@microsoft.com
Hi Simon,

> So after all this, do I understand that: 
> (a) Dare agrees with MSXML that my original schema[1] is invalid; 
> while 
> (b) Jeni originally agreed with Henry that it was OK, but now thinks
> it is unclear
> ?

Yes. I think that it's OK by the spirit of the Rec, but ambiguous by
the letter of the Rec.

> How can I define a base type that will accept *any* elements in its
> content model, and then define a type derived from this by
> restriction that confines the content to a specific vocabulary? (to
> be used for elements in a substitution group)

I think that what you had should work, and it does work with some
schema validators (e.g. Xerces-C++). However, here's a hack that will
get you round the issue...

Declare the basetype and the newtype to be a choice between the model
that you're actually interested in and an element that you'll define
elsewhere. To make this deterministic, the any wildcard and the
element that you use have to have different namespaces - I think that
you want the namespace for the wildcard to be the targetNamespace, so
the following should work:

<xs:import namespace="http://www.example.com/foo"
           schemaLocation="test2.xsd" />

<xs:complexType name="basetype">
    <xs:any maxOccurs="unbounded" namespace="##targetNamespace" />
    <xs:element ref="foo:foo" />

<xs:complexType name="newtype">
    <xs:restriction base="my:basetype">
          <xs:element name="e1" type="xs:string"/>
          <xs:element name="e2" type="xs:integer" minOccurs="0"/>
          <xs:element name="e3" type="xs:date" minOccurs="0"/>
        <xs:element ref="foo:foo" />

This way, MSXML recognises that the any wildcard is being restricted
to the sequence of elements, and doesn't complain about the 1 to many
mapping between particles.

Then declare the foo:foo element to be an abstract element in
'test2.xsd' (or whatever), and to block substitution:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

<xs:element name="foo" abstract="true" block="substitution" />


This ensures that the foo:foo element can never itself be used in an
instance document, and that it can't be substituted for another
element should someone import your schema.

I tested this with MSXML4 and it validates fine.



Jeni Tennison
Received on Tuesday, 12 March 2002 06:10:09 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:55 UTC