XML Schema syntax for derivation by restriction

We've been struggling to understand the XML syntax of restricted types, and
in particular what the effect should be of not listing an element or
attribute from the base type.  As I read the new revision of XML Structures,
it looks like

Any attribute declared in the base type can be used in instances of the
restricted type unless you explicitly say use="prohibited" in the restricted
type.  (You do not have to repeat attributes from the base type in order for
them to be used in instances of the restricted type.) 

Elements declared in the base type cannot be used in instances of the
restricted type unless you also list them in the definition of the
restricted type. So not mentioning an element from the base type is
equivalent to listing it with maxOccurs="0" in the restricted type.

However, I tried the following experiments with 3 different validating
parsers and got mixed results:

Base type for all tests is:

<complexType name="Basic">
   <sequence>
      <element ref="myns:Recipient"/>
      <element ref="myns:Street" minOccurs="0" maxOccurs="3"/>
      <element ref="myns:City"/>
      <element ref="myns:State"/>
      <element ref="myns:Zip" minOccurs="0"/>
   </sequence>
   <attribute name="ID" type="ID" use="required"/>
   <attribute name="Description" type="string"/>
</complexType>

<element name="Recipient" type="string"/>
<element name="Street" type="string"/>
<element name="City" type="string"/>
<element name="State" type="string"/>
<element name="Zip" type="integer"/>

Test 1:  Attribute Description is not listed in the restricted type

<element name="El1" type="myns:RestrictedAttrsOmit"/>
<complexType name="RestrictedAttrsOmit">
   <complexContent>
      <restriction base="myns:Basic">
   <sequence>
      <element ref="myns:Recipient"/>
      <element ref="myns:Street" minOccurs="0" maxOccurs="3"/>
      <element ref="myns:City"/>
      <element ref="myns:State"/>
      <element ref="myns:Zip"/>
   </sequence>
   <attribute name="ID" type="ID" use="required"/>
      </restriction>
   </complexContent>
</complexType>

<El1 ID="myID" Description="some text"
     xmlns="http://www.xerox.com/xmlschemas/MyNamespace"
     xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
     xsi:schemaLocation="http://www.xerox.com/xmlschemas/MyNamespace
Restriction.xsd">
   <Recipient>J. Slein</Recipient>
   <Street>309 West Ave.</Street>
   <City>Wilderness</City>
   <State>ME</State>
   <Zip>00001</Zip>
</El1>

Results:
XSV -- valid
XML Spy -- valid
XML Instance -- invalid

Test 2: Restricted type has Description with use="prohibited"

<element name="El2" type="myns:RestrictedAttrsProhibit"/>
<complexType name="RestrictedAttrsProhibit">
   <complexContent>
      <restriction base="myns:Basic">
   <sequence>
      <element ref="myns:Recipient"/>
      <element ref="myns:Street" minOccurs="0" maxOccurs="3"/>
      <element ref="myns:City"/>
      <element ref="myns:State"/>
      <element ref="myns:Zip"/>
   </sequence>
   <attribute name="ID" type="ID" use="required"/>
   <attribute name="Description" type="string" use="prohibited"/>
      </restriction>
   </complexContent>
</complexType>

<El2 ID="myID" Description="some text"
     xmlns="http://www.xerox.com/xmlschemas/MyNamespace"
     xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
     xsi:schemaLocation="http://www.xerox.com/xmlschemas/MyNamespace
Restriction.xsd">
   <Recipient>J. Slein</Recipient>
   <Street>309 West Ave.</Street>
   <City>Wilderness</City>
   <State>ME</State>
   <Zip>00001</Zip>
</El2>

Results:
XSV -- invalid
XML Spy -- invalid
XML Instance -- valid

Test 3: Element Zip is not listed in the restricted type

<element name="El3" type="myns:RestrictedElsOmit"/>
<complexType name="RestrictedElsOmit">
   <complexContent>
      <restriction base="myns:Basic">
   <sequence>
      <element ref="myns:Recipient"/>
      <element ref="myns:Street" minOccurs="0" maxOccurs="3"/>
      <element ref="myns:City"/>
      <element ref="myns:State"/>
   </sequence>
   <attribute name="ID" type="ID" use="required"/>
   <attribute name="Description" type="string"/>
      </restriction>
   </complexContent>
</complexType>

<El3 ID="myID" Description="some text"
     xmlns="http://www.xerox.com/xmlschemas/MyNamespace"
     xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
     xsi:schemaLocation="http://www.xerox.com/xmlschemas/MyNamespace
Restriction.xsd">
   <Recipient>J. Slein</Recipient>
   <Street>309 West Ave.</Street>
   <City>Wilderness</City>
   <State>ME</State>
   <Zip>00001</Zip>
</El3>

Results:
XSV -- invalid
XML Spy -- invalid
XML Instance -- invalid

Test 4: Element Zip has maxOccurs="0" in restricted type

<element name="El4" type="myns:RestrictedElsMaxOccurs"/>
<complexType name="RestrictedElsMaxOccurs">
   <complexContent>
      <restriction base="myns:Basic">
   <sequence>
      <element ref="myns:Recipient"/>
      <element ref="myns:Street" minOccurs="0" maxOccurs="3"/>
      <element ref="myns:City"/>
      <element ref="myns:State"/>
      <element ref="myns:Zip" minOccurs="0" maxOccurs="0"/>
   </sequence>
   <attribute name="ID" type="ID" use="required"/>
   <attribute name="Description" type="string"/>
      </restriction>
   </complexContent>
</complexType>

<El4 ID="myID" Description="some text"
     xmlns="http://www.xerox.com/xmlschemas/MyNamespace"
     xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
     xsi:schemaLocation="http://www.xerox.com/xmlschemas/MyNamespace
Restriction.xsd">
   <Recipient>J. Slein</Recipient>
   <Street>309 West Ave.</Street>
   <City>Wilderness</City>
   <State>ME</State>
   <Zip>00001</Zip>
</El4>

Results:
XSV -- valid
XML Spy -- valid
XML Instance -- invalid

Can someone explain what the results of these tests really should be and
why?  Thanks.

Judith A. Slein
Xerox Corporation
(716)422-5169
jslein@crt.xerox.com

Received on Monday, 19 March 2001 13:18:46 UTC