Re: import/include question

Sorry to be so slow, I've been traveling.

>> Please note that A.xsd and C.xsd have same targetNamespace N1.

Sorry, I did miss that.  The perils of answering in a hurry, which I'm 
afraid I'm doing again.

>> Do you mean that if you reference any component 
>> from other schema explicitly, then you must include/import 
>> this schema in the original schema **directly**? For example, 
>> in A.xsd, I must "include" c.xsd. correct?

There are some subtleties in this area of the spec, but I can only give 
you my reading.     First of all, you certainly don't want import.   The 
description of that makes clear that it is for use only when you need a 
namespace other than your targetNamespace.  See [1]  which says:

"As described in XML Schema Abstract Data Model (§2.2), every top-level 
schema component is associated with a target namespace (or, explicitly, 
with none). This section sets out the exact mechanism and syntax in the 
XML form of schema definition by which a reference to a foreign component 
is made, that is, a component with a different target namespace from that 
of the referring component."

...and then goes on to define <import>.

What about <include>.  Well, that's a bit murkier.  Taken in isolation, 
schema A is at risk of not working, for the obvious reason.  It's 
referring to an element declaration in its own target namespace, and it's 
not defining that element.  If it explicitly included c.xsd, then that 
uncertainty goes away.  So it's probably a good thing to do. 

What about the chain through B to C.Xsd?  That is (correctly) done with 
<import>, but note that on <import> the schemaLocation is a hint.  If you 
know that your processor will follow it, then things will work, but you 
might find processors that don't (most do.)  What will a processor do when 
it sees the import from B.xsd of C.xsd?  Will it say:  I've already got 
declarations for targetNamespace N1?   That's up to the processor.  Since 
the schemaLocation is a hint, it has license to not bring in C.Xsd at all 
(and we can't know whether the presence of A.xsd influenced its decision.) 
 Can it bring in C.xsd if it wants to?   My reading is yes.  Nothing I 
know in the recommendation prevents that gathering of definitions from a 
given namespace from multiple schema documents, as long as those 
defintions taken together form a coherent schema.  As a simpler example, 
it would be fine to build a processor that takes schema document names on 
the command line (possibly overriding hints in the <imports>, which is one 
of the reasons they are hints).  I see nothing that prevents naming two 
such documents that provide declarations for the same target namespace.

All of that said, you probably do want to do the direct <include>.  It's 
the reliable way of getting the behavior you want.  Hope I've got it right 
this time, and sorry for the delay in responding.

Noah

[1] http://www.w3.org/TR/xmlschema-1/#composition-schemaImport

------------------------------------------------------------------
Noah Mendelsohn                              Voice: 1-617-693-4036
IBM Corporation                                Fax: 1-617-693-8676
One Rogers Street
Cambridge, MA 02142
------------------------------------------------------------------







"Rajul Gupta" <rajul@oss.com>
05/14/2003 08:24 AM

 
        To:     <noah_mendelsohn@us.ibm.com>
        cc:     "XML Schema Dev" <xmlschema-dev@w3.org>
        Subject:        Re: import/include question


Hi Noah,

----- Original Message -----
From: <noah_mendelsohn@us.ibm.com>
To: "Rajul Gupta" <rajul@oss.com>
Cc: "XML Schema Dev" <xmlschema-dev@w3.org>
Sent: Tuesday, May 13, 2003 10:55 PM
Subject: Re: import/include question


> If I'm following your example, this is not legal because A.xsd has an
> explicit reference to a component from namespace http://www.example.com/N1
> but no import for that namespace.

Please note that A.xsd and C.xsd have same targetNamespace N1.

> The rule is, each document must declare
> its dependencies on anything it explicitly references.

Do you mean that if you reference any component from other schema
explicitly, then you must include/import this schema in the original 
schema
**directly**? For example, in A.xsd, I must "include" c.xsd. correct?

> Namespaces that
> are used implicitly (for example the base type of some type) need not be
> imported by your schema document.  I hope this helps.

Do you mean, had there been a base type in C.xsd, I could derive the base
type in A.xsd without direct "include"? Could you please explain this a
little more?

Thanks a lot for your help.

Regards,

Rajul

> ------------------------------------------------------------------
> Noah Mendelsohn                              Voice: 1-617-693-4036
> IBM Corporation                                Fax: 1-617-693-8676
> One Rogers Street
> Cambridge, MA 02142
> ------------------------------------------------------------------
>
>
>
>
>
>
>
> "Rajul Gupta" <rajul@oss.com>
> Sent by: xmlschema-dev-request@w3.org
> 05/13/2003 04:51 PM
>
>
>         To:     "XML Schema Dev" <xmlschema-dev@w3.org>
>         cc:     (bcc: Noah Mendelsohn/Cambridge/IBM)
>         Subject:        import/include question
>
>
> Hi,
>
> I have one question about the import/include. I have following three
> schemas. A.xsd and C.xsd have same targetNamespace N1; and B.xsd has
> targetNamespace N2. A.xsd imports B.xsd, and B.xsd imports C.xsd. Is 
this
> example legal since there is no direct "include" between A.xsd and 
C.xsd?
>
> Thanks in advance,
>
> Rajul
> 
--------------------------------------------------------------------------
> A.xsd:
>
> <xs:schema targetNamespace="http://www.example.com/N1"
>  xmlns:n2="http://www.example.com/N2"
>  xmlns:n1="http://www.example.com/N1"
>  xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
>  <xs:import namespace="http://www.example.com/N2" schemaLocation="b.xsd"/>
>
>  <xs:complexType name="MyType">
>   <xs:sequence>
>    <xs:element ref="n1:el"/>
>   </xs:sequence>
>  </xs:complexType>
>
>  <xs:element name="root" type="n1:MyType"/>
>
> </xs:schema>
>
> 
-------------------------------------------------------------------------
>
> B.xsd:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>  xmlns="http://www.example.com/N2"
>  targetNamespace="http://www.example.com/N2">
>
>  <xs:import schemaLocation="c.xsd" namespace="http://www.example.com/N1"/>
>
> </xs:schema>
>
> 
--------------------------------------------------------------------------
>
> C.xsd:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
>  xmlns="http://www.example.com/N1"
>  targetNamespace="http://www.example.com/N1">
>
>  <xs:element name="el" type="xs:integer"/>
>
> </xs:schema>
>
> 
-------------------------------------------------------------------------
>
>
>
>

Received on Thursday, 22 May 2003 13:37:51 UTC