Re: Adding children to type derived by restriction

Just to give you more information about Xerces and derivation restriction
checking....

Xerces 1.4.3 will detect an error for the derivation by restriction example
you show below, when the following feature is set:

"http://apache.org/xml/features/validation/schema-full-checking"

Xerces 2 Beta 3 (which has alpha-level Schema support) does not have full
Schema constraint checking (this should be available next month).   In
particular, our limitations page lists the following constraints which are
not yet checked in V2:
                      - Unique Particle Attribution;
                      - Particle Valid (Restriction);
                      - Element Declarations Consistent. .

Lisa.




Mark Feblowitz <mfeblowitz@frictionless.com>@w3.org on 11/06/2001 10:23:27
AM

Please respond to Mark Feblowitz <mfeblowitz@frictionless.com>

Sent by:  xmlschema-dev-request@w3.org


To:   "Xmlschema-Dev (E-mail)" <xmlschema-dev@w3.org>
cc:
Subject:  Adding children to type derived by restriction


I sent a similar message to Henry, but I also thought it would be useful to
break it open for wider discussion.


I am part of a team that is developing the Open Application Group's XML
Schema version of the OAGIS standard. Before we commit the grievous sin of
including illegal Schema constructs in a proposed standard(!), we thought
it a good idea to ask about particular usage that we're unsure of.


There seem to be diverse interpretations regarding allowable derivations of
complex types by restriction. The issue at hand is that of adding a new
child element to a complex type that has been derived by restriction. Our
understanding, based on reading the Schema Structures spec, is that this is
not allowed. But XML Spy, Xerces, and  XSV allow this behavior.


In the example below, complexType "RestrictionType" has been derived by
restriction from complexType "BaseType." Note that the child element "b"
has been removed and child element "B" has been added:


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault
="qualified" attributeFormDefault="unqualified">
    <xs:complexType name="BaseType">
        <xs:sequence>
            <xs:element name="a"/>
            <xs:element name="b"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="RestrictionType">
        <xs:complexContent>
            <xs:restriction base="BaseType">
                <xs:sequence>
                    <xs:element name="a"/>
                    <xs:element name="B"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:element name="ExampleElement" type="RestrictionType"/>
</xs:schema>

Our understanding is that this should not validate or, at very least, the
instance document should not validate:

<ExampleElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Example.xsd">
    <a/>
    <B/>
</ExampleElement>


Both the xsd and the instance file validate in XML Spy 4.1, Xerces 2.0.0b3,
and  XSV 1.3. Is this correct behavior? Why?


OK, if that is legal, then how about this: Are validators expected
(eventually?) to accept a specific element in any namespace as an
acceptable substitute for an "xs:any" in namespace "##any"?


<xs:complexType name="P">
    <xs:complexContent>
        <xs:extension base="xs:anyType"/>
    </xs:complexContent>
</xs:complexType>

Note: There seems to be some disagreement as to whether the the use of
"xs:anyType" is legal and correct. An alternative, I believe, would be:

P.xsd

<xs:complexType name="P">
    <xs:sequence>
        <xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

Now, say that we'd like to redefine and restrict that type so that the
"any" is replaced by a particular element, namely, "TheOnlyAllowedElement":

PR.xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault
="qualified" attributeFormDefault="unqualified">
    <xs:redefine schemaLocation="P.xsd">
        <xs:complexType name="P">
            <xs:complexContent>
                <xs:restriction base="P">
                    <xs:sequence>
                        <xs:element name="TheOnlyAllowedElement"/>
                    </xs:sequence>
                </xs:restriction>
            </xs:complexContent>
        </xs:complexType>
    </xs:redefine>
    <xs:element name="P" type="P"/>
</xs:schema>

This is similar in that it represents a derivation by restriction that also
adds a new child element. Let's say that validators start to complain about
extending a type derived by restriction. Would/should they complain about
the usage above? Strictly speaking, naming a particular element from a
particular namespace should satisfy the constraint that the derived type be
a proper subtype. But it's not clear to me that validation engines would be
equipped to properly figure out that that's what's happening here.

 BTW, all three validators mentioned above validate the following instance
doc:

pr1.xml:

    <P xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="PR.xsd">
        <TheOnlyAllowedElement/>
    </P>


These are not merely academic questions. They are important in our
decisions about how to use XML Schema in our standard.


Thanks,

Mark


Mark Feblowitz
XML Architect
Frictionless Commerce Incorporated
400 Technology Square, 9th floor
Cambridge, MA 02139
(617) 715-7231
mfeblowitz@frictionless.com

Received on Thursday, 8 November 2001 15:25:12 UTC