You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Inns, Jeff" <ji...@extol.com> on 2003/07/31 20:14:48 UTC

Import, Include and namespace

This is not exactly a Xerces question but a general XML Schema question.
 
If a schema ("my") imports two schemas ("a" and "b") and "a" & "b" include
"c", does "c" belong to the two different namespaces in "my"?  "my", "a" and
"b" have different targetNamespaces.
 
Schema "my":
 
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="file://c:/name-space"
xmlns:b="file://c:/name-space/b" xmlns:a="file://c:/name-space/a"
xmlns:name-space="file://c:/name-space"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
    <xs:import namespace="file://c:/name-space/a"
schemaLocation="file://c:/name-space/a/a.xsd"/>
    <xs:import namespace="file://c:/name-space/b"
schemaLocation="file://c:/name-space/b/b.xsd"/>
    <xs:element name="root">
    </xs:element>
</xs:schema>
 
Schema "a":
 
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="file://c:/name-space/a"
xmlns="file://c:/name-space/a" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:include schemaLocation="file://c:/name-space/c/c.xsd"/>
    <xs:element name="a">
    </xs:element>
</xs:schema>
 
Schema "b":
 
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="file://c:/name-space/b"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="file://c:/name-space/b"
elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:include schemaLocation="file://c:/name-space/c/c.xsd"/>
    <xs:element name="b">
    </xs:element>
</xs:schema>
 
Schema "c":
 
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="c">
</xs:element>
</xs:schema>
 

Re: Import, Include and namespace

Posted by Jeff Greif <jg...@alumni.princeton.edu>.
The rules are:
   1. Constructs in included schemas are defined in the target namespace of the including schema.  The included schema's namespace must match the targetNamespace of the includer, or it must have no namespace.
   2.  Import must be for schemas with namespaces different from the target namespace of the importer. The import element allows the importer to refer to the constructs of the imported schema, but does not add anything to the targetnamespace of the importer.

Thus:  
1.  a include c defines an element a:c  (where a: represents a's target namespace)
2.  b include c defines an element b:c
3.  my then can reference (through imports of a and b) the two elements a:c and b:c.
  
Jeff

  ----- Original Message ----- 
  From: Inns, Jeff 
  To: 'xerces-j-user@xml.apache.org' 
  Sent: Thursday, July 31, 2003 11:14 AM
  Subject: Import, Include and namespace


  This is not exactly a Xerces question but a general XML Schema question.

  If a schema ("my") imports two schemas ("a" and "b") and "a" & "b" include "c", does "c" belong to the two different namespaces in "my"?  "my", "a" and "b" have different targetNamespaces.