RE: I need help with some schema problems

Hi Adam:

I took the schema in your email and pasted in XMLSpy. It is well-formed and
valid, per XMLSpy.

Using conventional thinking, "xml data confirming to derived type should
also confirm to base type". In other words, all possible xml instances that
confirm to complexType "test4" should also be confirm to complexType "test".

>>>> the relevant part of your original schema

    <xs:element abstract="true" name="aba" type="xs:string"/>
    <xs:element abstract="true" name="abb" type="xs:int"/>
    <xs:element abstract="true" name="abc" type="xs:date"/>
    <xs:element name="a" substitutionGroup="aba" type="xs:string"/>
    <xs:element name="b" substitutionGroup="abb" type="xs:int"/>
    <xs:element name="c" substitutionGroup="abc" type="xs:date"/>
    <xs:element name="d" type="xs:anyURI"/>

    <xs:complexType name="test">
        <xs:sequence>
            <xs:group maxOccurs="unbounded" minOccurs="0" ref="abs"/>
            <xs:element minOccurs="0" ref="d"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="test4">
        <xs:complexContent>
            <xs:restriction base="test">
                <xs:sequence>
                    <xs:sequence minOccurs="1" maxOccurs="1">
                        <xs:element ref="a"/>
                        <xs:element ref="b"/>
                    </xs:sequence>
                    <xs:element ref="d"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:group name="abs">
        <xs:choice>
            <xs:element ref="aba"/>
            <xs:element ref="abb"/>
            <xs:element ref="abc"/>
        </xs:choice>
    </xs:group>

>>>>>>


If I had something like

<test4>
  <a>A</a>
  <b>10<b>
  <d>XYZ</d>
</test4>

This will be valid for type "test4" and "test".

Also, not knowing details related to problem domain, however, the schema
that you sent could be possibly be further simplified in terms of structure,
especially, the use of substitutionGroups.

Thanks,

Naren















-----Original Message-----
From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org]On
Behalf Of Adam van den Hoven
Sent: Monday, January 05, 2004 12:19 PM
To: xmlschema-dev@w3.org
Subject: I need help with some schema problems


Hi guys.

I'm writing a very large schema (currently more that 100k spread across
several files) and I've run into a hiccup that I can't seem to get my head
around.

I've included a schema that illustrates the problem I'm running into.

Can someone tell me why the complexType "test4" generates the following
validation error:

derivation-ok-restriction.5.4.2: Error for type 'test4'. The particle of the
type is not a valid restriction of the particle of the base.

I've validated this using OxygenXML (which I'm told uses Xerces).

Now, intuitively, this makes absolutely no sense. The base type (test)
allows any number of elements from the group "abs" and then an optional "d"
element. The first 3 restrictions are all valid and define a sequence of "a"
and "b" elements repeated some number of times followed by the "d". It seems
that so long as exactly one of each is not specified, the restrictions will
be valid. I can't see why having optional elements is valid but requiring
them one is not.

I want to say what is in test4 but I also want to keep all the abstractions.
Any thoughts?


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element abstract="true" name="aba" type="xs:string"/>
    <xs:element abstract="true" name="abb" type="xs:int"/>
    <xs:element abstract="true" name="abc" type="xs:date"/>
    <xs:element name="a" substitutionGroup="aba" type="xs:string"/>
    <xs:element name="b" substitutionGroup="abb" type="xs:int"/>
    <xs:element name="c" substitutionGroup="abc" type="xs:date"/>
    <xs:element name="d" type="xs:anyURI"/>
    <xs:complexType name="test">
        <xs:sequence>
            <xs:group maxOccurs="unbounded" minOccurs="0" ref="abs"/>
            <xs:element minOccurs="0" ref="d"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="test1">
        <xs:complexContent>
            <xs:restriction base="test">
                <xs:sequence>
                    <xs:sequence minOccurs="0" maxOccurs="1">
                        <xs:element ref="a"/>
                        <xs:element ref="b"/>
                    </xs:sequence>
                    <xs:element ref="d"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="test2">
        <xs:complexContent>
            <xs:restriction base="test">
                <xs:sequence>
                    <xs:sequence minOccurs="0" maxOccurs="0">
                        <xs:element ref="a"/>
                        <xs:element ref="b"/>
                    </xs:sequence>
                    <xs:element ref="d"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="test3">
        <xs:complexContent>
            <xs:restriction base="test">
                <xs:sequence>
                    <xs:sequence minOccurs="1" maxOccurs="2">
                        <xs:element ref="a"/>
                        <xs:element ref="b"/>
                    </xs:sequence>
                    <xs:element ref="d"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="test4">
        <xs:complexContent>
            <xs:restriction base="test">
                <xs:sequence>
                    <xs:sequence minOccurs="1" maxOccurs="1">
                        <xs:element ref="a"/>
                        <xs:element ref="b"/>
                    </xs:sequence>
                    <xs:element ref="d"/>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:group name="abs">
        <xs:choice>
            <xs:element ref="aba"/>
            <xs:element ref="abb"/>
            <xs:element ref="abc"/>
        </xs:choice>
    </xs:group>
</xs:schema>

Received on Monday, 5 January 2004 21:20:36 UTC