W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2001

Re: Wrapped around the axle: Refining and extending structures across namespaces

From: <mike_leditschke@nemmco.com.au>
Date: Thu, 20 Dec 2001 10:33:26 +1000
To: Jeni Tennison <jeni@jenitennison.com>
Cc: xmlschema-dev@w3.org
Message-ID: <OF4D6F671A.3769D138-ON4A256B28.00004B70@nemmco.com.au>

Hi Jeni. I was interested in your use of substitution groups
in this example. I have not done much with schemas covering
multiple namespaces, so it raised a few questions in my (poor)
understanding of this area.

1. Am I correct to assume a substitution group can contain elements
from multiple namespaces as your example using ns2 suggests?

2. I thought all elements in a substitution group had to be derived
from a common type, which itself must be in a particular namespace.
Presumably the effect of the element definitions in ns2 create *elements*
in ns2, whose base content model is that of the *type* of the element
in ns1 that is the head of the substitution group.

3. What is the effect of elementFormDefault in the two schemas? For
if the head (say in ns1) defines some base content and uses  a form
default of qualifed, but the substitution element extending this (say in
uses unqualified, does an instance using the the element from ns2 have both
base and extended content unqualified, or the base stuff qualified and the
extension stuff unqualified, or all qualified?

4. Does the same apply to the use of xsi:type? For instance, can a type in
extend a type in ns1 and be substituted for ns1 on an element allowing such
substitution? I presume whatever your answer re form default above
would apply equally to to this situation?


                    Jeni Tennison                                                                                       
                    <jeni@jenitennison        To:     Mark Feblowitz <mfeblowitz@frictionless.com>                      
                    .com>                     cc:     "Xmlschema-Dev (E-mail)" <xmlschema-dev@w3.org>                   
                    Sent by:                  Subject:     Re: Wrapped around the axle: Refining and extending          
                    xmlschema-dev-requ        structures across namespaces                                              
                    20/12/2001 09:48                                                                                    
                    Please respond to                                                                                   
                    Jeni Tennison                                                                                       

Hi Mark,

> The two major difficulties I encounter are 1) keeping the refinement
> and extension appropriately separate and 2) keeping namespace
> prefixing in the instance document simple and manageable.

You raise some very interesting issues. In particular, this
demonstrates the tension between wanting to maintain a neat type
hierarchy and wanting to validate neat instance documents.

My view is that your first priority should be getting the instance
document to look the way that you want it to look. Most applications
that deal with XML do not care about the schema and the neat type
hierarchy that you might use within it. They do care, very much, about
the namespaces of the elements in the document.

The instance document:

<Document xmlns="ns2" xmlns:ns1="ns1"

Is very different, to any namespace-aware processor from, for example:

<Document xmlns:ns2="ns2" xmlns="ns1"

In most cases, I'd imagine that you'd like a processor that could deal
with documents described by the ns1 schema to be able to process the
instance document that includes the ns2 schema. That means, I think,
that the second instance document is the one that you'll be aiming

Once you've decided what you want your instance document to look like,
your choices are clearer.

First option: since you cannot redefine the content of an element in
the ns1 namespace from within a schema whose target location is the
ns2 namespace, if you want to change the possible content of the
Document and Header elements, you can create an 'adapter' schema with
ns1 as the target namespace. Within the adapter schema, you can
redefine the basic ns1 schema, extending the various types as
required. So you can do:

<xs:schema targetNamespace="ns1" xmlns="ns1" xmlns:ns2="ns2"

<xs:import namespace="ns2"
           schemaLocation="RefineExtend-NS2.xsd" />

<xs:redefine schemaLocation="RefineExtend-NS1.xsd">

  <xs:complexType name="DocumentType">
      <xs:extension base="DocumentType">
          <xs:element ref="ns2:Footer" />

  <xs:complexType name="HeaderType">
      <xs:extension base="HeaderType">
          <xs:element ref="ns2:LastModifiedDate" />



The schema for ns2 then simply declares the Footer and
LastModifiedDate elements.

In a way this *does* maintain the 'neat type hierarchy' - the type of
the Document used in documents containing ns2 is an extension of the
type of the Document used in documents that only contain ns1.

Second option: you can implicitly 'extend' the content of an element
if you place within it a placeholder for the extensions. If you don't
need a lot of control, you can do so with wildcards; if you want more
control, you can use substitution groups. For example, in the schema
for ns1, you could use abstract element declarations to act as
placeholders for extended content:

<xs:schema targetNamespace="ns1" xmlns="ns1"

<xs:element name="Document" type="DocumentType"/>

<xs:complexType name="DocumentType">
    <xs:element name="Header" type="HeaderType"/>
    <xs:element name="Line" type="LineType" maxOccurs="unbounded"/>
    <xs:element ref="DocumentExtension"
                minOccurs="0" maxOccurs="unbounded" />

<xs:element name="DocumentExtension" abstract="true" />

<xs:complexType name="HeaderType">
    <xs:element name="CreationDate" type="xs:date"/>
    <xs:element ref="HeaderExtension"
                minOccurs="0" maxOccurs="unbounded" />

<xs:element name="HeaderExtension" abstract="true" />

<xs:complexType name="LineType">
    <xs:element name="LineNumber" type="xs:positiveInteger"/>


In the schema for ns2, you can then declare the elements that get
added to the types in ns1 as belonging to the relevant substitution

<xs:element name="Footer"
            ... />
<xs:element name="LastModifiedDate"
            ... />

This has the advantage that you don't have to make new 'adapter'
schemas every time you want to add new elements to the content models.

Note that neither of these methods need to use restriction to force
Document elements to hold Header elements with an extended type.



Jeni Tennison

This e-mail is confidential.  If you are not the intended recipient, any use, disclosure or copying of this document is unauthorised and prohibited.  If you have received this document in error, please delete the email and notify me by return email or by phoning the NEMMCO Helpdesk on 1300 300 295.
Received on Wednesday, 19 December 2001 19:34:40 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:25 GMT