Coupled Chameleon Components?

Hi Folks,

I have been telling everyone that a constraint on creating no-namespace
components (Chameleon components) is that they must not be coupled
(i.e., one component cannot reference another) because the coupling will
break when the no-namespace schema is <include>d into a schema with a
targetNamespace.  Now, I am thinking that that is not true.

Consider this no-namespace schema:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
        elementFormDefault="qualified">
    <xsd:complexType name="CardCatalogueEntry">
        <xsd:sequence>
            <xsd:element name="Title" type="xsd:string"/>
            <xsd:element name="Author" type="xsd:string"/>
            <xsd:element name="Date" type="xsd:string"/>
            <xsd:element name="ISBN" type="xsd:string"/>
            <xsd:element name="Publisher" type="xsd:string" />
        </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="Book" type="CardCatalogueEntry"/>
</xsd:schema>

[As an aside: what meaning does elementFormDefault have with
no-namespace schemas?]

This schema has two components - a complexType CardCatalogueEntry
component and an element Book component.  The Book component references
the CardCatalogueEntry component. 

Consider what happens when these components are included in a schema
with a namespace.  Let's consider two scenarios:

[1] The including schema has XMLSchema as the default namespace:

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2000/10/XMLSchema"
        targetNamespace="http://www.library.org"
        elementFormDefault="qualified"
        xmlns:lib="http://www.library.org">
    <include schemaLocation="BookCatalogue.xsd"/>
    <element name="Library">
        <complexType>
             <sequence>
                 <element name="BookCatalogue">
                     <complexType>
                         <sequence>
                             <element ref="lib:Book"/>
                         </sequence>
                     </complexType>
            </sequence>
        </complexType>
    </element>
</schema>

Clearly, the reference of Book to CardCatalogueEntry in the no-namespace
schema:

    <xsd:element name="Book" type="CardCatalogueEntry"/>

will fail since CardCatalogueEntry is no longer in no-namespace.

Question: consider the Book element declaration after the Library schema
includes BookCatalogue.xsd:

    <xsd:element name="Book" type="CardCatalogueEntry"/>

Is Book referencing CardCatalogueEntry in the default namespace (which
is the XMLSchema namespace), or is it referencing CardCatalogueEntry in
no-namespace?  I believe that it is the former.  In which case, the
simple solution to enabling coupled Chameleon components is case 2:

[2] The including schema has the targetNamespace as the default
namespace:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
        targetNamespace="http://www.library.org"
        xmlns="http://www.library.org"
        elementFormDefault="qualified">
    <xsd:include schemaLocation="BookCatalogue.xsd"/>
    <xsd:element name="Library">
        <xsd:complexType>
             <xsd:sequence>
                 <xsd:element name="BookCatalogue">
                     <xsd:complexType>
                         <xsd:sequence>
                             <xsd:element ref="Book"/>
                         </xsd:sequence>
                     </xsd:complexType>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

Note that the targetNamespace is the default namespace.  When the
no-namespace components (Book and CardCatalogueEntry) are included in
this schema they take on the targetNamespace.  Consequently, this
element declaration in the no-namespace schema:

    <xsd:element name="Book" type="CardCatalogueEntry"/>

should be referencing a CardCatalogueEntry component in the
targetNamespace. Or, is Book still referencing CardCatalogueEntry in
no-namespace?  

When I ran this example, using the scenario 2 schema, in XSV I got this
error message:

Undefined type {None}:CardCatalogueEntry referenced as type definition
of Book

This would seem to suggest that:

    <xsd:element name="Book" type="CardCatalogueEntry"/>

is still referencing the CardCatalogueEntry in no-namespace (as opposed
to a reference to CardCatalogueEntry in the default namespace).

There are two possibilities:

{1} XSV has a bug and type="CardCatalogueEntry" is a reference to the
CardCatalogueEntry in the default namespace (which in my schema is the
targetNamespace)

{2} There is no bug in XSV and type="CardCatalogueEntry" is a reference
to the CardCatalogueEntry in no-namespace, and XSV's error message is
valid.

Note: if {1} is the case then it has tremendous implications on Best
Practices.  /Roger

Received on Thursday, 22 February 2001 18:39:09 UTC