SlideShare a Scribd company logo
1 of 17
Download to read offline
Zero, One, or Many Namespaces?
Table of Contents
               Issue
               Introduction
               Example
                 Heterogeneous Namespace Design
                 Homogeneous Namespace Design
                 Chameleon Namespace Design

         Impact of Design Approach on Instance Documents
         <redefine> - only Applicable to Homogeneous and Chameleon Namespace Designs
         Default Namespace and the Chameleon Namespace Design
         Avoiding Name Collisions with Chameleon Components
         Creating Tools for Chameleon Components
         Best Practice

Issue:
In a project where multiple schemas are created, should we give each schema a different
targetNamespace, or should we give all the schemas the same targetNamespace, or should some
of the schemas have no targetNamespace?



               Managing Multiple Schemas - Same or
                  Different targetNamespaces?


                                                      ...


                                                              Schema-n.xsd
           Schema-1.xsd           Schema-2.xsd


                          … or no targetNamespace?


                                             28
Introduction
In a typical project many schemas will be created. The schema designer is then confronted with
this issue: “shall I define one targetNamespace for all the schemas, or shall I create a different
targetNamespace for each schema, or shall I have some schemas with no targetNamespace?”
What are the tradeoffs? What guidance would you give someone starting on a project that will
create multiple schemas?

Here are the three design approaches for dealing with this issue:

            [1] Heterogeneous Namespace Design:
                give each schema a different targetNamespace
            [2] Homogeneous Namespace Design:
                give all schemas the same targetNamespace
            [3] Chameleon Namespace Design:
                give the “main” schema a targetNamespace and give no
                targetNamespace to the “supporting” schemas (the no-namespace
                supporting schemas will take-on the targetNamespace of the main
                schema, just like a Chameleon)
To describe and judge the merits of the three design approaches it will be useful to take an
example and see each approach “in action”.

Example: XML Data Model of a Company
Imagine a project which involves creating a model of a company using XML Schemas. One very
simple model is to divide the schema functionality along these lines:

            Company schema
              Person schema
              Product schema

“A company is comprised of people and products.”

Here are the company, person, and product schemas using the three design approaches.




                                                29
[1] Heterogeneous Namespace Design
This design approach says to give each schema a different targetNamespace, e.g.,



                                                        <xsd:schema …
     <xsd:schema …
                                                            targetNamespace=quot;Bquot;>
         targetNamespace=quot;Aquot;>
                                                                    B.xsd
           A.xsd

                 <xsd:schema …
                          targetNamespace=quot;Cquot;>
                     <xsd:import namespace=quot;Aquot;
                                 schemaLocation=quot;A.xsdquot;/>
                     <xsd:import namespace=quot;Bquot;
                                 schemaLocation=quot;B.xsdquot;/>
                     …
                 </xsd:schema>
                                     C.xsd


Below are the three schemas designed using this design approach. Observe that each schema has
a different targetNamespace.

Product.xsd


   <?xml version=quot;1.0quot;?>
   <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
                targetNamespace=quot;http://www.product.orgquot;
                xmlns=quot;http://www.product.orgquot;
                elementFormDefault=quot;qualifiedquot;>
     <xsd:complexType name=quot;ProductTypequot;>
       <xsd:sequence>
          <xsd:element name=quot;Typequot; type=quot;xsd:stringquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/>
       </xsd:sequence>
     </xsd:complexType>
   </xsd:schema>




                                              30
Person.xsd


             <?xml version=quot;1.0quot;?>
             <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
                           targetNamespace=quot;http://www.person.orgquot;
                          xmlns=quot;http://www.person.orgquot;
                          elementFormDefault=quot;qualifiedquot;>
               <xsd:complexType name=quot;PersonTypequot;>
                 <xsd:sequence>
                    <xsd:element name=quot;Namequot; type=quot;xsd:stringquot;/>
                    <xsd:element name=quot;SSNquot; type=quot;xsd:stringquot;/>
                 </xsd:sequence>
               </xsd:complexType>
             </xsd:schema>


Company.xsd

                <?xml version=quot;1.0quot;?>
                <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
                              targetNamespace=quot;http://www.company.orgquot;
                              xmlns=quot;http://www.company.orgquot;
                             elementFormDefault=quot;qualifiedquot;
                             xmlns:per=quot;http://www.person.orgquot;
                             xmlns:pro=quot;http://www.product.orgquot;>
                  <xsd:import namespace=quot;http://www.person.orgquot;
                         schemaLocation=quot;Person.xsdquot;/>
                  <xsd:import namespace=quot;http://www.product.orgquot;
                         schemaLocation=quot;Product.xsdquot;/>
                  <xsd:element name=quot;Companyquot;>
                     <xsd:complexType>
                       <xsd:sequence>
                         <xsd:element name=quot;Personquot; type=quot;per:PersonTypequot; maxOccurs=quot;unboundedquot;/>
                         <xsd:element name=quot;Productquot; type=quot;pro:ProductTypequot; maxOccurs=quot;unboundedquot;/>
                       </xsd:sequence>
                     </xsd:complexType>
                  </xsd:element>
                </xsd:schema>




Note the three namespaces that were created by the schemas:

              http://www.product.org
              http://www.person.org
              http://www.company.org




                                                       31
[2] Homogeneous Namespace Design
This design approach says to create a single, umbrella targetNamespace for all the schemas, e.g.,



  <xsd:schema …                                      <xsd:schema …
      targetNamespace=quot;Libraryquot;>                         targetNamespace=quot;Libraryquot;>
   LibraryBookCatalogue.xsd                                LibraryEmployees.xsd




     <xsd:schema …
              targetNamespace=quot;Libraryquot;>
         <xsd:include schemaLocation=quot;LibraryBookCatalogue.xsdquot;/>
         <xsd:include schemaLocation=quot;LibraryEmployees.xsdquot;/>
         …
     </xsd:schema>
                                       Library.xsd


Below are the three schemas designed using this approach. Observe that all schemas have the
same targetNamespace.

Product.xsd


       <?xml version=quot;1.0quot;?>
       <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
                    targetNamespace=quot;http://www.company.orgquot;
                    xmlns=quot;http://www.product.orgquot;
                    elementFormDefault=quot;qualifiedquot;>
         <xsd:complexType name=quot;ProductTypequot;>
            <xsd:sequence>
              <xsd:element name=quot;Typequot; type=quot;xsd:stringquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/>
            </xsd:sequence>
         </xsd:complexType>
       </xsd:schema>




                                               32
Person.xsd


              <?xml version=quot;1.0quot;?>
              <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
                           targetNamespace=quot;http://www.company.orgquot;
                           xmlns=quot;http://www.person.orgquot;
                           elementFormDefault=quot;qualifiedquot;>
                <xsd:complexType name=quot;PersonTypequot;>
                   <xsd:sequence>
                     <xsd:element name=quot;Namequot; type=quot;xsd:stringquot;/>
                     <xsd:element name=quot;SSNquot; type=quot;xsd:stringquot;/>
                   </xsd:sequence>
                </xsd:complexType>
              </xsd:schema>


Company.xsd


      <?xml version=quot;1.0quot;?>
      <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
                   targetNamespace=quot;http://www.company.orgquot;
                   xmlns=quot;http://www.company.orgquot;
                   elementFormDefault=quot;qualifiedquot;>
        <xsd:include schemaLocation=quot;Person.xsdquot;/>
        <xsd:include schemaLocation=quot;Product.xsdquot;/>
        <xsd:element name=quot;Companyquot;>
           <xsd:complexType>
             <xsd:sequence>
                <xsd:element name=quot;Personquot; type=quot;PersonTypequot; maxOccurs=quot;unboundedquot;/>
                <xsd:element name=quot;Productquot; type=quot;ProductTypequot; maxOccurs=quot;unboundedquot;/>
             </xsd:sequence>
           </xsd:complexType>
        </xsd:element>
      </xsd:schema>


Note that all three schemas have the same targetNamespace:

              http://www.company.org

Also note the mechanism used for accessing components in other schemas which have the same
targetNamespace: <include>. When accessing components in a schema with a different
namespace the <import> element is used, as we saw above in the Heterogeneous Design.




                                             33
[3] Chameleon Namespace Design
This design approach says to give the “main” schema a targetNamespace, and the “supporting”
schemas have no targetNamespace, e.g.,



          <xsd:schema …>                                      <xsd:schema …>

            Q.xsd                                                   R.xsd




             <xsd:schema …
                      targetNamespace=quot;Zquot;>
                 <xsd:include schemaLocation=quot;Q.xsdquot;/>
                 <xsd:include schemaLocation=quot;R.xsdquot;/>
                 …
             </xsd:schema>
                                       Z.xsd


In our example, the company schema is the main schema. The person and product schemas are
supporting schemas. Below are the three schemas using this design approach:

Product.xsd (no targetNamespace)

     <?xml version=quot;1.0quot;?>
     <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
                  elementFormDefault=quot;qualifiedquot;>
       <xsd:complexType name=quot;ProductTypequot;>
         <xsd:sequence>
            <xsd:element name=quot;Typequot; type=quot;xsd:stringquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/>
         </xsd:sequence>
       </xsd:complexType>
     </xsd:schema>




                                             34
Person.xsd (no targetNamespace)


     <?xml version=quot;1.0quot;?>
     <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
                  elementFormDefault=quot;qualifiedquot;>
       <xsd:complexType name=quot;PersonTypequot;>
         <xsd:sequence>
            <xsd:element name=quot;Namequot; type=quot;xsd:stringquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/>
            <xsd:element name=quot;SSNquot; type=quot;xsd:stringquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/>
         </xsd:sequence>
       </xsd:complexType>
     </xsd:schema>


Company.xsd (main schema, uses the no-namespace-schemas)


       <?xml version=quot;1.0quot;?>
       <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
                    targetNamespace=quot;http://www.company.orgquot;
                    xmlns=quot;http://www.company.orgquot;
                    elementFormDefault=quot;qualifiedquot;>
         <xsd:include schemaLocation=quot;Person.xsdquot;/>
         <xsd:include schemaLocation=quot;Product.xsdquot;/>
         <xsd:element name=quot;Companyquot;>
            <xsd:complexType>
              <xsd:sequence>
                 <xsd:element name=quot;Personquot; type=quot;PersonTypequot; maxOccurs=quot;unboundedquot;/>
                 <xsd:element name=quot;Productquot; type=quot;ProductTypequot; maxOccurs=quot;unboundedquot;/>
              </xsd:sequence>
            </xsd:complexType>
         </xsd:element>
       </xsd:schema>


There are two things to note about this design approach:

First, as shown above, a schema is able to access components in schemas that have no
targetNamespace, using <include>. In our example, the company schema uses the components in
Product.xsd and Person.xsd (and they have no targetNamespace).

Second, note the chameleon-like characteristics of schemas with no targetNamespace:
– The components in the schemas with no targetNamespace get namespace-coerced. That is, the
  components “take-on” the targetNamespace of the schema that is doing the <include>.
For example, ProductType in Products.xsd gets implicitly coerced into the company
targetNamespace.

                                               35
“Chameleon effect” ... This is a term coined by Henry Thompson to describe the ability of
components in a schema with no targetNamespace to take-on the namespace of other schemas.
This is powerful!

Impact of Design Approach on Instance Documents
Above we have shown how the schemas would be designed using the three design approaches.
Let’s turn now to the instance document. Does an instance document differ depending on the
design approach? All of the above schemas have been designed to expose the namespaces in
instance documents (as directed by: elementFormDefault=“qualified”). If they had instead all
used elementFormDefault=“unqualified” then instance documents would all have this form:


                   <?xml version=quot;1.0quot;?>
                   <c:Company xmlns:c=quot;http://www.company.orgquot;
                               xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot;
                               xsi:schemaLocation=
                                       quot;http://www.company.org
                                        Company.xsdquot;>
                        <Person>
                             <Name>John Doe</Name>
                             <SSN>123-45-6789</SSN>
                        </Person>
                        <Product>
                             <Type>Widget</Type>
                        </Product>
                   </c:Company>


It is when the schemas expose their namespaces in instance documents that differences appear. In
the above schemas, they all specified elementFormDefault=“qualified”, thus exposing their
namespaces in instance documents. Let’s see what the instance documents look like for each
design approach:

[1] Company.xml (conforming to the multiple targetNamespaces version)


                   <?xml version=quot;1.0quot;?>
                   <Company xmlns=quot;http://www.company.orgquot;
                              xmlns:per=quot;http://www.person.orgquot;
                              xmlns:prod=quot;http://www.product.orgquot;
                              xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot;
                              xsi:schemaLocation=
                                       quot;http://www.company.org
                                        Company.xsdquot;>
                       <Person>
                            <per:Name>John Doe</per:Name>
                            <per:SSN>123-45-6789</per:SSN>
                       </Person>
                       <Product>
                            <prod:Type>Widget</prod:Type>
                       </Product>
                   </Company>



                                                  36
Note that:
– there needs to be a namespace declaration for each namespace
– the elements must all be uniquely qualified (explicitly or with a default namespace)
[2] Company.xml (conforming to the single, umbrella targetNamespace version)


                  <?xml version=quot;1.0quot;?>
                  <Company xmlns=quot;http://www.company.orgquot;
                             xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot;
                             xsi:schemaLocation=
                                     quot;http://www.company.org
                                      Company.xsdquot;>
                      <Person>
                           <Name>John Doe</Name>
                           <SSN>123-45-6789</SSN>
                      </Person>
                      <Product>
                           <Type>Widget</Type>
                      </Product>
                  </Company>



Since all the schemas are in the same namespace the instance document is able to take advantage
of that by using a default namespace.

[3] Company.xml (conforming to the main targetNamespace with supporting no-
targetNamespace version)


                  <?xml version=quot;1.0quot;?>
                  <Company xmlns=quot;http://www.company.orgquot;
                             xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot;
                             xsi:schemaLocation=
                                      quot;http://www.company.org
                                       Company.xsdquot;>
                      <Person>
                           <Name>John Doe</Name>
                           <SSN>123-45-6789</SSN>
                      </Person>
                      <Product>
                           <Type>Widget</Type>
                      </Product>
                  </Company>


Both of the schemas that have no targetNamespace take on the the company targetNamespace
(ala the Chameleon effect). Thus, all components are in the same targetNamespace and the
instance document takes advantage of this by declaring a default namespace.




                                                37
<redefine> - only Applicable to Homogeneous and Chameleon Namespace Designs
The <redefine> element is used to enable access to components in another schema, while
simultaneously giving the capability to modify zero or more of the components. Thus, the
<redefine> element has a dual functionality:
– it does an implicit <include>. Thus it enables access to all the components in the referenced
  schema
– it enables you to redefine zero or more of the components in the referenced schema, i.e.,
  extend or restrict components
Example. Consider again the Company.xsd schema above. Suppose that it wishes to use
ProductType in Product.xsd. However, it would like to extend ProductType to include a product
ID. Here’s how to do it using redefine:



            <?xml version=quot;1.0quot;?>
            <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;
                         targetNamespace=quot;http://www.company.orgquot;
                         xmlns=quot;http://www.company.orgquot;
                         elementFormDefault=quot;qualifiedquot;>
              <xsd:include schemaLocation=quot;Person.xsdquot;/>
              <xsd:redefine schemaLocation=quot;Product.xsdquot;>
                <xsd:complexType name=quot;ProductTypequot;>
                   <xsd:complexContent>
                     <xsd:extension base=quot;ProductTypequot;>
                        <xsd:sequence>
                          <xsd:element name=quot;IDquot; type=quot;xsd:IDquot;/>
                        </xsd:sequence>
                     </xsd:extension>
                   </xsd:complexContent>
                </xsd:complexType>
              </xsd:redefine>
              <xsd:element name=quot;Companyquot;>
                <xsd:complexType>
                   <xsd:sequence>
                     <xsd:element name=quot;Personquot; type=quot;PersonTypequot; maxOccurs=quot;unboundedquot;/>
                     <xsd:element name=quot;Productquot; type=quot;ProductTypequot; maxOccurs=quot;unboundedquot;/>
                   </xsd:sequence>
                </xsd:complexType>
              </xsd:element>
            </xsd:schema>




Now the <Product> element in instance documents will contain both <Type> and <ID>, e.g.,




                                                  38
<?xml version=quot;1.0quot;?>
                  <Company xmlns=quot;http://www.company.orgquot;
                             xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot;
                             xsi:schemaLocation=
                                    quot;http://www.company.org
                                     Company.xsdquot;>
                      <Person>
                           <Name>John Doe</Name>
                           <SSN>123-45-6789</SSN>
                      </Person>
                      <Product>
                           <Type>Widget</Type>
                           <ID>1001-1-00</ID>
                      </Product>
                  </Company>


The <redefine> element is very powerful. However, it can only be used with schemas with the
same targetNamespace or with no targetNamespace. Thus, it only applies to the Homogenous
Namespace Design and the Chameleon Namespace Design.

Name collisions
When a schema uses Chameleon components those components become part of the including
schema’s targetNamespace, just as though the schema author had typed the element declarations
and type definitions inline. If the schema <include>s multiple no-namespace schemas then there
will be a chance of name collisions. In fact, the schema may end up not being able to use some of
the no-namespace schemas because their use results in name collisions with other Chameleon
components. To demonstrate the name collision problem, consider this example:

Suppose that there are two schemas with no targetNamespace:

            1.xsd
               A
               B
            2.xsd
             A
             C

Schema 1 creates no-namespace elements A and B. Schema 2 creates no-namespace elements A,
and C. Now if schema 3 <include>s these two no-namespace schemas there will be a name
collision:

            3.xsd
            targetNamespace=“http://www.example.org”
            <include schemaLocation=“1.xsd”/>
            <include schemaLocation=“2.xsd”/>




                                                39
This schema has a name collision - A is defined twice. [Note: it’s not an error to have two
elements in the same symbol space, provided they have the same type. However, if they have a
different type then it is an error, i.e., name collision.]

Namespaces are the standard way of avoiding such collisions. Above, if instead the components
in 1.xsd and 2.xsd resided in different namespaces then 3.xsd could have <import>ed them and
there would be no name collision. [Recall that two elements/types can have the same name if the
elements/types are in different namespaces.]

How do we address the name collision problem that the Chameleon design presents? That’s next.

Resolving Namespace Collisions using Proxy Schemas
There is a very simple solution to the namespace collision problem: for each no-namespace
schema create a companion namespaced-schema (a “proxy schema”) that <include>s the no-
namespace schema. Then, the main schema <import>s the proxy schemas.


                  <xsd:schema …>                                 <xsd:schema …>

                       Q.xsd                                          R.xsd


       <xsd:schema …                                    <xsd:schema …
                targetNamespace=quot;Z1quot;>                            targetNamespace=quot;Z2quot;>
           <xsd:include schemaLocation=quot;Q.xsdquot;/>            <xsd:include schemaLocation=quot;R.xsdquot;/>

               Q-Proxy.xsd                                                R-Proxy.xsd



                <xsd:schema …         targetNamespace=quot;Zquot;>
                    <xsd:import namespace=quot;Z1quot; schemaLocation=quot;Q-Proxy.xsdquot;/>
                    <xsd:import namespace=quot;Z2quot; schemaLocation=quot;R-Proxy.xsdquot;/>
                    …
                </xsd:schema>

                                               Z.xsd



With this approach we avoid name collisions. This design approach has the added advantage that
it also enables the proxy schemas to customize the Chameleon components using <redefine>.

Thus, this approach is a two-step process:
               Create the Chameleon schemas
               Create a proxy schema for each Chameleon schema

The “main” schema <import>s the proxy schemas.

The advantage of this two-step approach is that it enables applications to decide on a domain
(namespace) for the components that it is reusing. Furthermore, applications are able to refine/



                                                   40
customize the Chameleon components. This approach requires an extra step (i.e., creating proxy
schemas) but in return it provides a lot of flexibility.

Contrast the above two-step process with the below one-step process where the components are
assigned to a namespace from the very beginning:

            1-fixed.xsd
            targetNamespace=“http://www.1-fixed.org”
               A
               B
            2-fixed.xsd
            targetNamespace=“http://www.2-fixed.org”
             A
             C
            main.xsd
            targetNamespace=“http://www.main.org”
            <xsd:import namespace=“http://www.1-fixed.org”
                  schemaLocation=“1-fixed.xsd”/>
            <xsd:import namespace=“http://www.2-fixed.org”
                  schemaLocation=“2-fixed.xsd”/>

This achieves the same result as the above two-step version. In this example, the components are
not Chameleon. Instead, A, B, and C were hardcoded with a namespace from the very beginning
of their life. The downside of this approach is that if main.xsd wants to <redefine> any of the
elements it cannot. Also, applications are forced to use a domain (namespace) defined by
someone else. These components are in a rigid, static, fixed namespace.

Creating Tools for Chameleon Components
Tools for Chameleon Components
We have seen repeatedly how Chameleon components are able to blend in with the schemas that
use them. That is, they adopt the namespace of the schema that <include>s them.

                                           <xsd:schema …>




                                                         <xsd:schema …
             <xsd:schema …
                                                               targetNamespace=quot;Z2quot;>
                      targetNamespace=quot;Z1quot;>
                                                          <xsd:include schemaLocation=”Q.xsdquot;/>
                 <xsd:include schemaLocation=quot;Q.xsdquot;/>




                 Chameleon components take-on the namespace of the <include>ing schema




                                                    41
How do you write tools for components that can assume so many different faces (namespaces)?



                                                                   Tool
                                     <xsd:schema …>
                                                                     ?


                                                   <xsd:schema …
      <xsd:schema …
                                                         targetNamespace=quot;Z2quot;>
               targetNamespace=quot;Z1quot;>
                                                    <xsd:include schemaLocation=”Q.xsdquot;/>
          <xsd:include schemaLocation=quot;Q.xsdquot;/>




               How does a tool identify components that can assume many faces?
               Certainly not by namespaces.


Consider this no-namespace schema:

            1.xsd
              A
              B

Suppose that we wish to create a tool, T, which must process the two Chameleon components A
and B, regardless of what namespace they reside in. The tool must be able to handle the
following situation: imagine a schema, main.xsd, which <include>s 1.xsd. In addition, suppose
that main.xsd has its own element called A (in a different symbol space, so there’s no name
collision). For example:

            main.xsd
            targetNamespace=“http://www.example.org”
            <include schemaLocation=“1.xsd”/>
            <element name=“stuff”>
              <complexType>
               <sequence>
                 <element name=“A” type=“xxx”/>
                 ...
               </sequence>
              </complexType>
            </element>

How would the tool T be able to distinguish between the Chameleon component A and the local
A in an instance document?




                                              42
Chameleon Component Identification
One simple solution is that when you create Chameleon components assign them a global unique
id (a GUID). The XML Schema spec allows you to add an attribute, id, to all element, attribute,
complexType, and simpleType components.

             <xsd:element name=quot;Lat_Lonquot;
                          id=quot;http://www.geospacial.orgquot;
                          …
             </xsd:element>

            Each component (element, complexType, simpleType, attribute)
            in a schema can have an associated id attribute. This can be used
            to uniquely identify each Chameleon component, regardless of
            its namespace.

Note that the id attribute is purely local to the schema. There is no representation in the instance
documents. This id attribute could be used by a tool to “locate” a Chameleon component,
regardless of what “face” (namespace) it currently wears. That is, the tool can open up an
instance document using DOM, and the DOM API will provide the tool access to the id value for
all components in the instance document.


                                       <xsd:schema …>
                                                                            Tool
                                       id=quot;www.geospacial.orgquot;




                                                         <xsd:schema …
    <xsd:schema …
                                                               targetNamespace=quot;Z2quot;>
             targetNamespace=quot;Z1quot;>
                                                          <xsd:include schemaLocation=”Q.xsdquot;/>
        <xsd:include schemaLocation=quot;Q.xsdquot;/>


                                                                  id=quot;www.geospacial.orgquot;
             id=quot;www.geospacial.orgquot;




      A tool can locate the Chameleon component by using the id attribute.

Best Practice
Above we explored the “design space” for this issue. We looked at the three design approaches in
action, both schemas and instance documents. So which design is better? Under what
circumstances?



                                                   43
When you are reusing schemas that someone else created you should <import> those schemas,
i.e., use the Heterogeneous Namespace design. It is a bad idea to copy those components into
your namespace, for two reasons: (1) soon your local copies would get out of sync with the other
schemas, and (2) you lose interoperability with any existing applications that process the other
schema’s components. The interesting case (the case we have been considering throughout this
discussion) is how to deal with namespaces in a collection of schemas that you created. Here’s
our guidelines for this case:

Use the Chameleon Design:
– with schemas which contain components that have no inherent semantics by themselves,
– with schemas which contain components that have semantics only in the context of an
  <include>ing schema,
– when you don’t want to hardcode a namespace to a schema, rather you want <include>ing
  schemas to be able to provide their own application-specific namespace to the schema
Example. A repository of components - such as a schema which defines an array type, or vector,
linked list, etc - should be declared with no targetNamespace (i.e., Chameleon).

As a rule of thumb, if your schema just contains type definitions (no element declarations) then
that schema is probably a good candidate for being a Chameleon schema.

Use the Homogeneous Namespace Design
• when all of your schemas are conceptually related
• when there is no need to visually identify in instance documents the origin/lineage of each
  element/attribute. In this design all components come from the same namespace, so you loose
  the ability to identify in instance documents that “element A comes from schema X”.
  Oftentimes that’s okay - you don’t want to categorize elements/attributes differently. This
  design approach is well suited for those situations.
Use the Heterogeneous Namespace Design
• when there are multiple elements with the same name. (Avoid name collision)
• when there is a need to visually identify in instance documents the origin/lineage of each
  element/attribute. In this design the components come from different namespaces, so you have
  the ability to identify in instance documents that “element A comes from schema X”.
Lastly, as we have seen, in a schema each component can be uniquely identified with an id
attribute (this is NOT the same as providing an id attribute on an element in instance documents.
We are talking here about a schema-internal way of identifying each schema component.)
Consider identifying each schema component using the id attribute. This will enable a finer
degree of traceability than is possible using namespaces. The combination of namespaces plus
the schema id attribute is a powerful tandem for visually and programmatically identifying
components.




                                               44

More Related Content

What's hot

Caracteristicas Basicas De Htlm
Caracteristicas Basicas De HtlmCaracteristicas Basicas De Htlm
Caracteristicas Basicas De Htlm
Maria S Rivera
 
Ifi7174 lesson2
Ifi7174 lesson2Ifi7174 lesson2
Ifi7174 lesson2
Sónia
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
Tesfaye Yenealem
 
Internet programming lab manual
Internet programming lab manualInternet programming lab manual
Internet programming lab manual
inteldualcore
 

What's hot (20)

Caracteristicas Basicas De Htlm
Caracteristicas Basicas De HtlmCaracteristicas Basicas De Htlm
Caracteristicas Basicas De Htlm
 
An Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java ScriptAn Overview of HTML, CSS & Java Script
An Overview of HTML, CSS & Java Script
 
Ifi7174 lesson2
Ifi7174 lesson2Ifi7174 lesson2
Ifi7174 lesson2
 
Chicken pox-3541974
Chicken pox-3541974Chicken pox-3541974
Chicken pox-3541974
 
Ifi7174 lesson1
Ifi7174 lesson1Ifi7174 lesson1
Ifi7174 lesson1
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
 
Joomla! Template for Beginners
Joomla! Template for BeginnersJoomla! Template for Beginners
Joomla! Template for Beginners
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
 
WCBuf: CSS Display Properties versus HTML Semantics
WCBuf: CSS Display Properties versus HTML SemanticsWCBuf: CSS Display Properties versus HTML Semantics
WCBuf: CSS Display Properties versus HTML Semantics
 
Sightly - Part 2
Sightly - Part 2Sightly - Part 2
Sightly - Part 2
 
Web Design for Literary Theorists II: Overview of CSS (v 1.0)
Web Design for Literary Theorists II: Overview of CSS (v 1.0)Web Design for Literary Theorists II: Overview of CSS (v 1.0)
Web Design for Literary Theorists II: Overview of CSS (v 1.0)
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End Methodologies
 
HTML 5 Simple Tutorial Part 1
HTML 5 Simple Tutorial Part 1HTML 5 Simple Tutorial Part 1
HTML 5 Simple Tutorial Part 1
 
Supercharged HTML & CSS
Supercharged HTML & CSSSupercharged HTML & CSS
Supercharged HTML & CSS
 
Couch Db.0.9.0.Pub
Couch Db.0.9.0.PubCouch Db.0.9.0.Pub
Couch Db.0.9.0.Pub
 
Web front end development introduction to html css and javascript
Web front end development introduction to html css and javascriptWeb front end development introduction to html css and javascript
Web front end development introduction to html css and javascript
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
 
Web Typography
Web TypographyWeb Typography
Web Typography
 
Internet programming lab manual
Internet programming lab manualInternet programming lab manual
Internet programming lab manual
 
HTML Foundations, pt 2
HTML Foundations, pt 2HTML Foundations, pt 2
HTML Foundations, pt 2
 

Viewers also liked (8)

Interim Management En Marketing
Interim Management En MarketingInterim Management En Marketing
Interim Management En Marketing
 
Hibernate Shards
Hibernate ShardsHibernate Shards
Hibernate Shards
 
PanteóN
PanteóNPanteóN
PanteóN
 
COB_20090127_1
COB_20090127_1COB_20090127_1
COB_20090127_1
 
Ebean
EbeanEbean
Ebean
 
Java Play RESTful ebean
Java Play RESTful ebeanJava Play RESTful ebean
Java Play RESTful ebean
 
Global Vision Identity
Global Vision Identity Global Vision Identity
Global Vision Identity
 
Scuba Camera
Scuba CameraScuba Camera
Scuba Camera
 

Similar to Zero One Or Many Namespaces

Hide Versus Expose
Hide Versus ExposeHide Versus Expose
Hide Versus Expose
LiquidHub
 
Global Versus Local
Global Versus LocalGlobal Versus Local
Global Versus Local
LiquidHub
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
Suite Solutions
 
Default Namespace
Default NamespaceDefault Namespace
Default Namespace
LiquidHub
 
XML Business Rules Validation with Schematron
XML Business Rules Validation with SchematronXML Business Rules Validation with Schematron
XML Business Rules Validation with Schematron
Emiel Paasschens
 

Similar to Zero One Or Many Namespaces (20)

Hide Versus Expose
Hide Versus ExposeHide Versus Expose
Hide Versus Expose
 
Ridingapachecamel
RidingapachecamelRidingapachecamel
Ridingapachecamel
 
Global Versus Local
Global Versus LocalGlobal Versus Local
Global Versus Local
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise Monitor
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handling
 
Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schema
 
JSON Viewer XPATH Workbook
JSON Viewer XPATH WorkbookJSON Viewer XPATH Workbook
JSON Viewer XPATH Workbook
 
Expanding a tree node
Expanding a tree nodeExpanding a tree node
Expanding a tree node
 
Default Namespace
Default NamespaceDefault Namespace
Default Namespace
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazos
 
Java script
Java scriptJava script
Java script
 
Seam Glassfish Slidecast
Seam Glassfish SlidecastSeam Glassfish Slidecast
Seam Glassfish Slidecast
 
Mazda Use of Third Generation Xml Tools
Mazda Use of Third Generation Xml ToolsMazda Use of Third Generation Xml Tools
Mazda Use of Third Generation Xml Tools
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For Xml
 
IBM Lotus Notes Domino XPages and XPages for Mobile
IBM Lotus Notes Domino XPages and XPages for MobileIBM Lotus Notes Domino XPages and XPages for Mobile
IBM Lotus Notes Domino XPages and XPages for Mobile
 
XML Business Rules Validation with Schematron
XML Business Rules Validation with SchematronXML Business Rules Validation with Schematron
XML Business Rules Validation with Schematron
 
OOW 2012 XML Business Rules Validation Schematron - Emiel Paasschens
OOW 2012  XML Business Rules Validation Schematron - Emiel PaasschensOOW 2012  XML Business Rules Validation Schematron - Emiel Paasschens
OOW 2012 XML Business Rules Validation Schematron - Emiel Paasschens
 
Schematron
SchematronSchematron
Schematron
 
Nanoformats
NanoformatsNanoformats
Nanoformats
 

More from LiquidHub

Sharepoint 2013 upgrade process
Sharepoint 2013 upgrade processSharepoint 2013 upgrade process
Sharepoint 2013 upgrade process
LiquidHub
 
Share point 2013
Share point 2013Share point 2013
Share point 2013
LiquidHub
 
Share point 2010-uiimprovements
Share point 2010-uiimprovementsShare point 2010-uiimprovements
Share point 2010-uiimprovements
LiquidHub
 
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
LiquidHub
 
Managing metadata in_share_point_2010
Managing metadata in_share_point_2010Managing metadata in_share_point_2010
Managing metadata in_share_point_2010
LiquidHub
 
Fast search for share point
Fast search for share pointFast search for share point
Fast search for share point
LiquidHub
 
Simple Farm Server Deployment
Simple Farm Server DeploymentSimple Farm Server Deployment
Simple Farm Server Deployment
LiquidHub
 
Pre Install Databases
Pre Install DatabasesPre Install Databases
Pre Install Databases
LiquidHub
 
Moss 2007 Deployment Detail
Moss 2007 Deployment DetailMoss 2007 Deployment Detail
Moss 2007 Deployment Detail
LiquidHub
 
Moss 2007 Backup Strategies
Moss 2007 Backup StrategiesMoss 2007 Backup Strategies
Moss 2007 Backup Strategies
LiquidHub
 
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
LiquidHub
 
5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps
LiquidHub
 
Working With Infopath 2007
Working With Infopath 2007Working With Infopath 2007
Working With Infopath 2007
LiquidHub
 
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature WalkthroughWhats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
LiquidHub
 
Overviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshOverviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components Refresh
LiquidHub
 
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 RefreshOrganizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
LiquidHub
 

More from LiquidHub (20)

Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0Share point 2013 coding standards and best practices 1.0
Share point 2013 coding standards and best practices 1.0
 
Sharepoint 2013 upgrade process
Sharepoint 2013 upgrade processSharepoint 2013 upgrade process
Sharepoint 2013 upgrade process
 
Share point 2013
Share point 2013Share point 2013
Share point 2013
 
Share point 2010-uiimprovements
Share point 2010-uiimprovementsShare point 2010-uiimprovements
Share point 2010-uiimprovements
 
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
Microsoft office-sharepoint-server-2007-presentation-120211522467022-2
 
Managing metadata in_share_point_2010
Managing metadata in_share_point_2010Managing metadata in_share_point_2010
Managing metadata in_share_point_2010
 
Fast search for share point
Fast search for share pointFast search for share point
Fast search for share point
 
Simple Farm Server Deployment
Simple Farm Server DeploymentSimple Farm Server Deployment
Simple Farm Server Deployment
 
Pre Install Databases
Pre Install DatabasesPre Install Databases
Pre Install Databases
 
Moss 2007 Deployment Detail
Moss 2007 Deployment DetailMoss 2007 Deployment Detail
Moss 2007 Deployment Detail
 
Moss 2007 Backup Strategies
Moss 2007 Backup StrategiesMoss 2007 Backup Strategies
Moss 2007 Backup Strategies
 
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
How To Configure Email Enabled Lists In Moss2007 Rtm Using Exchange 2003
 
Bdc Screens
Bdc ScreensBdc Screens
Bdc Screens
 
Bdc Screens
Bdc ScreensBdc Screens
Bdc Screens
 
5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps
 
5060 A 01
5060 A 015060 A 01
5060 A 01
 
Working With Infopath 2007
Working With Infopath 2007Working With Infopath 2007
Working With Infopath 2007
 
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature WalkthroughWhats New In Microsoft Windows Share Point Services Feature Walkthrough
Whats New In Microsoft Windows Share Point Services Feature Walkthrough
 
Overviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshOverviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components Refresh
 
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 RefreshOrganizingand Finding Resourceswith Office Share Point Server2007 Refresh
Organizingand Finding Resourceswith Office Share Point Server2007 Refresh
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Zero One Or Many Namespaces

  • 1. Zero, One, or Many Namespaces? Table of Contents Issue Introduction Example Heterogeneous Namespace Design Homogeneous Namespace Design Chameleon Namespace Design Impact of Design Approach on Instance Documents <redefine> - only Applicable to Homogeneous and Chameleon Namespace Designs Default Namespace and the Chameleon Namespace Design Avoiding Name Collisions with Chameleon Components Creating Tools for Chameleon Components Best Practice Issue: In a project where multiple schemas are created, should we give each schema a different targetNamespace, or should we give all the schemas the same targetNamespace, or should some of the schemas have no targetNamespace? Managing Multiple Schemas - Same or Different targetNamespaces? ... Schema-n.xsd Schema-1.xsd Schema-2.xsd … or no targetNamespace? 28
  • 2. Introduction In a typical project many schemas will be created. The schema designer is then confronted with this issue: “shall I define one targetNamespace for all the schemas, or shall I create a different targetNamespace for each schema, or shall I have some schemas with no targetNamespace?” What are the tradeoffs? What guidance would you give someone starting on a project that will create multiple schemas? Here are the three design approaches for dealing with this issue: [1] Heterogeneous Namespace Design: give each schema a different targetNamespace [2] Homogeneous Namespace Design: give all schemas the same targetNamespace [3] Chameleon Namespace Design: give the “main” schema a targetNamespace and give no targetNamespace to the “supporting” schemas (the no-namespace supporting schemas will take-on the targetNamespace of the main schema, just like a Chameleon) To describe and judge the merits of the three design approaches it will be useful to take an example and see each approach “in action”. Example: XML Data Model of a Company Imagine a project which involves creating a model of a company using XML Schemas. One very simple model is to divide the schema functionality along these lines: Company schema Person schema Product schema “A company is comprised of people and products.” Here are the company, person, and product schemas using the three design approaches. 29
  • 3. [1] Heterogeneous Namespace Design This design approach says to give each schema a different targetNamespace, e.g., <xsd:schema … <xsd:schema … targetNamespace=quot;Bquot;> targetNamespace=quot;Aquot;> B.xsd A.xsd <xsd:schema … targetNamespace=quot;Cquot;> <xsd:import namespace=quot;Aquot; schemaLocation=quot;A.xsdquot;/> <xsd:import namespace=quot;Bquot; schemaLocation=quot;B.xsdquot;/> … </xsd:schema> C.xsd Below are the three schemas designed using this design approach. Observe that each schema has a different targetNamespace. Product.xsd <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; targetNamespace=quot;http://www.product.orgquot; xmlns=quot;http://www.product.orgquot; elementFormDefault=quot;qualifiedquot;> <xsd:complexType name=quot;ProductTypequot;> <xsd:sequence> <xsd:element name=quot;Typequot; type=quot;xsd:stringquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/> </xsd:sequence> </xsd:complexType> </xsd:schema> 30
  • 4. Person.xsd <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; targetNamespace=quot;http://www.person.orgquot; xmlns=quot;http://www.person.orgquot; elementFormDefault=quot;qualifiedquot;> <xsd:complexType name=quot;PersonTypequot;> <xsd:sequence> <xsd:element name=quot;Namequot; type=quot;xsd:stringquot;/> <xsd:element name=quot;SSNquot; type=quot;xsd:stringquot;/> </xsd:sequence> </xsd:complexType> </xsd:schema> Company.xsd <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; targetNamespace=quot;http://www.company.orgquot; xmlns=quot;http://www.company.orgquot; elementFormDefault=quot;qualifiedquot; xmlns:per=quot;http://www.person.orgquot; xmlns:pro=quot;http://www.product.orgquot;> <xsd:import namespace=quot;http://www.person.orgquot; schemaLocation=quot;Person.xsdquot;/> <xsd:import namespace=quot;http://www.product.orgquot; schemaLocation=quot;Product.xsdquot;/> <xsd:element name=quot;Companyquot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;Personquot; type=quot;per:PersonTypequot; maxOccurs=quot;unboundedquot;/> <xsd:element name=quot;Productquot; type=quot;pro:ProductTypequot; maxOccurs=quot;unboundedquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> Note the three namespaces that were created by the schemas: http://www.product.org http://www.person.org http://www.company.org 31
  • 5. [2] Homogeneous Namespace Design This design approach says to create a single, umbrella targetNamespace for all the schemas, e.g., <xsd:schema … <xsd:schema … targetNamespace=quot;Libraryquot;> targetNamespace=quot;Libraryquot;> LibraryBookCatalogue.xsd LibraryEmployees.xsd <xsd:schema … targetNamespace=quot;Libraryquot;> <xsd:include schemaLocation=quot;LibraryBookCatalogue.xsdquot;/> <xsd:include schemaLocation=quot;LibraryEmployees.xsdquot;/> … </xsd:schema> Library.xsd Below are the three schemas designed using this approach. Observe that all schemas have the same targetNamespace. Product.xsd <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; targetNamespace=quot;http://www.company.orgquot; xmlns=quot;http://www.product.orgquot; elementFormDefault=quot;qualifiedquot;> <xsd:complexType name=quot;ProductTypequot;> <xsd:sequence> <xsd:element name=quot;Typequot; type=quot;xsd:stringquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/> </xsd:sequence> </xsd:complexType> </xsd:schema> 32
  • 6. Person.xsd <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; targetNamespace=quot;http://www.company.orgquot; xmlns=quot;http://www.person.orgquot; elementFormDefault=quot;qualifiedquot;> <xsd:complexType name=quot;PersonTypequot;> <xsd:sequence> <xsd:element name=quot;Namequot; type=quot;xsd:stringquot;/> <xsd:element name=quot;SSNquot; type=quot;xsd:stringquot;/> </xsd:sequence> </xsd:complexType> </xsd:schema> Company.xsd <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; targetNamespace=quot;http://www.company.orgquot; xmlns=quot;http://www.company.orgquot; elementFormDefault=quot;qualifiedquot;> <xsd:include schemaLocation=quot;Person.xsdquot;/> <xsd:include schemaLocation=quot;Product.xsdquot;/> <xsd:element name=quot;Companyquot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;Personquot; type=quot;PersonTypequot; maxOccurs=quot;unboundedquot;/> <xsd:element name=quot;Productquot; type=quot;ProductTypequot; maxOccurs=quot;unboundedquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> Note that all three schemas have the same targetNamespace: http://www.company.org Also note the mechanism used for accessing components in other schemas which have the same targetNamespace: <include>. When accessing components in a schema with a different namespace the <import> element is used, as we saw above in the Heterogeneous Design. 33
  • 7. [3] Chameleon Namespace Design This design approach says to give the “main” schema a targetNamespace, and the “supporting” schemas have no targetNamespace, e.g., <xsd:schema …> <xsd:schema …> Q.xsd R.xsd <xsd:schema … targetNamespace=quot;Zquot;> <xsd:include schemaLocation=quot;Q.xsdquot;/> <xsd:include schemaLocation=quot;R.xsdquot;/> … </xsd:schema> Z.xsd In our example, the company schema is the main schema. The person and product schemas are supporting schemas. Below are the three schemas using this design approach: Product.xsd (no targetNamespace) <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; elementFormDefault=quot;qualifiedquot;> <xsd:complexType name=quot;ProductTypequot;> <xsd:sequence> <xsd:element name=quot;Typequot; type=quot;xsd:stringquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/> </xsd:sequence> </xsd:complexType> </xsd:schema> 34
  • 8. Person.xsd (no targetNamespace) <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; elementFormDefault=quot;qualifiedquot;> <xsd:complexType name=quot;PersonTypequot;> <xsd:sequence> <xsd:element name=quot;Namequot; type=quot;xsd:stringquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/> <xsd:element name=quot;SSNquot; type=quot;xsd:stringquot; minOccurs=quot;1quot; maxOccurs=quot;1quot;/> </xsd:sequence> </xsd:complexType> </xsd:schema> Company.xsd (main schema, uses the no-namespace-schemas) <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; targetNamespace=quot;http://www.company.orgquot; xmlns=quot;http://www.company.orgquot; elementFormDefault=quot;qualifiedquot;> <xsd:include schemaLocation=quot;Person.xsdquot;/> <xsd:include schemaLocation=quot;Product.xsdquot;/> <xsd:element name=quot;Companyquot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;Personquot; type=quot;PersonTypequot; maxOccurs=quot;unboundedquot;/> <xsd:element name=quot;Productquot; type=quot;ProductTypequot; maxOccurs=quot;unboundedquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> There are two things to note about this design approach: First, as shown above, a schema is able to access components in schemas that have no targetNamespace, using <include>. In our example, the company schema uses the components in Product.xsd and Person.xsd (and they have no targetNamespace). Second, note the chameleon-like characteristics of schemas with no targetNamespace: – The components in the schemas with no targetNamespace get namespace-coerced. That is, the components “take-on” the targetNamespace of the schema that is doing the <include>. For example, ProductType in Products.xsd gets implicitly coerced into the company targetNamespace. 35
  • 9. “Chameleon effect” ... This is a term coined by Henry Thompson to describe the ability of components in a schema with no targetNamespace to take-on the namespace of other schemas. This is powerful! Impact of Design Approach on Instance Documents Above we have shown how the schemas would be designed using the three design approaches. Let’s turn now to the instance document. Does an instance document differ depending on the design approach? All of the above schemas have been designed to expose the namespaces in instance documents (as directed by: elementFormDefault=“qualified”). If they had instead all used elementFormDefault=“unqualified” then instance documents would all have this form: <?xml version=quot;1.0quot;?> <c:Company xmlns:c=quot;http://www.company.orgquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xsi:schemaLocation= quot;http://www.company.org Company.xsdquot;> <Person> <Name>John Doe</Name> <SSN>123-45-6789</SSN> </Person> <Product> <Type>Widget</Type> </Product> </c:Company> It is when the schemas expose their namespaces in instance documents that differences appear. In the above schemas, they all specified elementFormDefault=“qualified”, thus exposing their namespaces in instance documents. Let’s see what the instance documents look like for each design approach: [1] Company.xml (conforming to the multiple targetNamespaces version) <?xml version=quot;1.0quot;?> <Company xmlns=quot;http://www.company.orgquot; xmlns:per=quot;http://www.person.orgquot; xmlns:prod=quot;http://www.product.orgquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xsi:schemaLocation= quot;http://www.company.org Company.xsdquot;> <Person> <per:Name>John Doe</per:Name> <per:SSN>123-45-6789</per:SSN> </Person> <Product> <prod:Type>Widget</prod:Type> </Product> </Company> 36
  • 10. Note that: – there needs to be a namespace declaration for each namespace – the elements must all be uniquely qualified (explicitly or with a default namespace) [2] Company.xml (conforming to the single, umbrella targetNamespace version) <?xml version=quot;1.0quot;?> <Company xmlns=quot;http://www.company.orgquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xsi:schemaLocation= quot;http://www.company.org Company.xsdquot;> <Person> <Name>John Doe</Name> <SSN>123-45-6789</SSN> </Person> <Product> <Type>Widget</Type> </Product> </Company> Since all the schemas are in the same namespace the instance document is able to take advantage of that by using a default namespace. [3] Company.xml (conforming to the main targetNamespace with supporting no- targetNamespace version) <?xml version=quot;1.0quot;?> <Company xmlns=quot;http://www.company.orgquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xsi:schemaLocation= quot;http://www.company.org Company.xsdquot;> <Person> <Name>John Doe</Name> <SSN>123-45-6789</SSN> </Person> <Product> <Type>Widget</Type> </Product> </Company> Both of the schemas that have no targetNamespace take on the the company targetNamespace (ala the Chameleon effect). Thus, all components are in the same targetNamespace and the instance document takes advantage of this by declaring a default namespace. 37
  • 11. <redefine> - only Applicable to Homogeneous and Chameleon Namespace Designs The <redefine> element is used to enable access to components in another schema, while simultaneously giving the capability to modify zero or more of the components. Thus, the <redefine> element has a dual functionality: – it does an implicit <include>. Thus it enables access to all the components in the referenced schema – it enables you to redefine zero or more of the components in the referenced schema, i.e., extend or restrict components Example. Consider again the Company.xsd schema above. Suppose that it wishes to use ProductType in Product.xsd. However, it would like to extend ProductType to include a product ID. Here’s how to do it using redefine: <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; targetNamespace=quot;http://www.company.orgquot; xmlns=quot;http://www.company.orgquot; elementFormDefault=quot;qualifiedquot;> <xsd:include schemaLocation=quot;Person.xsdquot;/> <xsd:redefine schemaLocation=quot;Product.xsdquot;> <xsd:complexType name=quot;ProductTypequot;> <xsd:complexContent> <xsd:extension base=quot;ProductTypequot;> <xsd:sequence> <xsd:element name=quot;IDquot; type=quot;xsd:IDquot;/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> </xsd:redefine> <xsd:element name=quot;Companyquot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;Personquot; type=quot;PersonTypequot; maxOccurs=quot;unboundedquot;/> <xsd:element name=quot;Productquot; type=quot;ProductTypequot; maxOccurs=quot;unboundedquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> Now the <Product> element in instance documents will contain both <Type> and <ID>, e.g., 38
  • 12. <?xml version=quot;1.0quot;?> <Company xmlns=quot;http://www.company.orgquot; xmlns:xsi=quot;http://www.w3.org/2001/XMLSchema-instancequot; xsi:schemaLocation= quot;http://www.company.org Company.xsdquot;> <Person> <Name>John Doe</Name> <SSN>123-45-6789</SSN> </Person> <Product> <Type>Widget</Type> <ID>1001-1-00</ID> </Product> </Company> The <redefine> element is very powerful. However, it can only be used with schemas with the same targetNamespace or with no targetNamespace. Thus, it only applies to the Homogenous Namespace Design and the Chameleon Namespace Design. Name collisions When a schema uses Chameleon components those components become part of the including schema’s targetNamespace, just as though the schema author had typed the element declarations and type definitions inline. If the schema <include>s multiple no-namespace schemas then there will be a chance of name collisions. In fact, the schema may end up not being able to use some of the no-namespace schemas because their use results in name collisions with other Chameleon components. To demonstrate the name collision problem, consider this example: Suppose that there are two schemas with no targetNamespace: 1.xsd A B 2.xsd A C Schema 1 creates no-namespace elements A and B. Schema 2 creates no-namespace elements A, and C. Now if schema 3 <include>s these two no-namespace schemas there will be a name collision: 3.xsd targetNamespace=“http://www.example.org” <include schemaLocation=“1.xsd”/> <include schemaLocation=“2.xsd”/> 39
  • 13. This schema has a name collision - A is defined twice. [Note: it’s not an error to have two elements in the same symbol space, provided they have the same type. However, if they have a different type then it is an error, i.e., name collision.] Namespaces are the standard way of avoiding such collisions. Above, if instead the components in 1.xsd and 2.xsd resided in different namespaces then 3.xsd could have <import>ed them and there would be no name collision. [Recall that two elements/types can have the same name if the elements/types are in different namespaces.] How do we address the name collision problem that the Chameleon design presents? That’s next. Resolving Namespace Collisions using Proxy Schemas There is a very simple solution to the namespace collision problem: for each no-namespace schema create a companion namespaced-schema (a “proxy schema”) that <include>s the no- namespace schema. Then, the main schema <import>s the proxy schemas. <xsd:schema …> <xsd:schema …> Q.xsd R.xsd <xsd:schema … <xsd:schema … targetNamespace=quot;Z1quot;> targetNamespace=quot;Z2quot;> <xsd:include schemaLocation=quot;Q.xsdquot;/> <xsd:include schemaLocation=quot;R.xsdquot;/> Q-Proxy.xsd R-Proxy.xsd <xsd:schema … targetNamespace=quot;Zquot;> <xsd:import namespace=quot;Z1quot; schemaLocation=quot;Q-Proxy.xsdquot;/> <xsd:import namespace=quot;Z2quot; schemaLocation=quot;R-Proxy.xsdquot;/> … </xsd:schema> Z.xsd With this approach we avoid name collisions. This design approach has the added advantage that it also enables the proxy schemas to customize the Chameleon components using <redefine>. Thus, this approach is a two-step process: Create the Chameleon schemas Create a proxy schema for each Chameleon schema The “main” schema <import>s the proxy schemas. The advantage of this two-step approach is that it enables applications to decide on a domain (namespace) for the components that it is reusing. Furthermore, applications are able to refine/ 40
  • 14. customize the Chameleon components. This approach requires an extra step (i.e., creating proxy schemas) but in return it provides a lot of flexibility. Contrast the above two-step process with the below one-step process where the components are assigned to a namespace from the very beginning: 1-fixed.xsd targetNamespace=“http://www.1-fixed.org” A B 2-fixed.xsd targetNamespace=“http://www.2-fixed.org” A C main.xsd targetNamespace=“http://www.main.org” <xsd:import namespace=“http://www.1-fixed.org” schemaLocation=“1-fixed.xsd”/> <xsd:import namespace=“http://www.2-fixed.org” schemaLocation=“2-fixed.xsd”/> This achieves the same result as the above two-step version. In this example, the components are not Chameleon. Instead, A, B, and C were hardcoded with a namespace from the very beginning of their life. The downside of this approach is that if main.xsd wants to <redefine> any of the elements it cannot. Also, applications are forced to use a domain (namespace) defined by someone else. These components are in a rigid, static, fixed namespace. Creating Tools for Chameleon Components Tools for Chameleon Components We have seen repeatedly how Chameleon components are able to blend in with the schemas that use them. That is, they adopt the namespace of the schema that <include>s them. <xsd:schema …> <xsd:schema … <xsd:schema … targetNamespace=quot;Z2quot;> targetNamespace=quot;Z1quot;> <xsd:include schemaLocation=”Q.xsdquot;/> <xsd:include schemaLocation=quot;Q.xsdquot;/> Chameleon components take-on the namespace of the <include>ing schema 41
  • 15. How do you write tools for components that can assume so many different faces (namespaces)? Tool <xsd:schema …> ? <xsd:schema … <xsd:schema … targetNamespace=quot;Z2quot;> targetNamespace=quot;Z1quot;> <xsd:include schemaLocation=”Q.xsdquot;/> <xsd:include schemaLocation=quot;Q.xsdquot;/> How does a tool identify components that can assume many faces? Certainly not by namespaces. Consider this no-namespace schema: 1.xsd A B Suppose that we wish to create a tool, T, which must process the two Chameleon components A and B, regardless of what namespace they reside in. The tool must be able to handle the following situation: imagine a schema, main.xsd, which <include>s 1.xsd. In addition, suppose that main.xsd has its own element called A (in a different symbol space, so there’s no name collision). For example: main.xsd targetNamespace=“http://www.example.org” <include schemaLocation=“1.xsd”/> <element name=“stuff”> <complexType> <sequence> <element name=“A” type=“xxx”/> ... </sequence> </complexType> </element> How would the tool T be able to distinguish between the Chameleon component A and the local A in an instance document? 42
  • 16. Chameleon Component Identification One simple solution is that when you create Chameleon components assign them a global unique id (a GUID). The XML Schema spec allows you to add an attribute, id, to all element, attribute, complexType, and simpleType components. <xsd:element name=quot;Lat_Lonquot; id=quot;http://www.geospacial.orgquot; … </xsd:element> Each component (element, complexType, simpleType, attribute) in a schema can have an associated id attribute. This can be used to uniquely identify each Chameleon component, regardless of its namespace. Note that the id attribute is purely local to the schema. There is no representation in the instance documents. This id attribute could be used by a tool to “locate” a Chameleon component, regardless of what “face” (namespace) it currently wears. That is, the tool can open up an instance document using DOM, and the DOM API will provide the tool access to the id value for all components in the instance document. <xsd:schema …> Tool id=quot;www.geospacial.orgquot; <xsd:schema … <xsd:schema … targetNamespace=quot;Z2quot;> targetNamespace=quot;Z1quot;> <xsd:include schemaLocation=”Q.xsdquot;/> <xsd:include schemaLocation=quot;Q.xsdquot;/> id=quot;www.geospacial.orgquot; id=quot;www.geospacial.orgquot; A tool can locate the Chameleon component by using the id attribute. Best Practice Above we explored the “design space” for this issue. We looked at the three design approaches in action, both schemas and instance documents. So which design is better? Under what circumstances? 43
  • 17. When you are reusing schemas that someone else created you should <import> those schemas, i.e., use the Heterogeneous Namespace design. It is a bad idea to copy those components into your namespace, for two reasons: (1) soon your local copies would get out of sync with the other schemas, and (2) you lose interoperability with any existing applications that process the other schema’s components. The interesting case (the case we have been considering throughout this discussion) is how to deal with namespaces in a collection of schemas that you created. Here’s our guidelines for this case: Use the Chameleon Design: – with schemas which contain components that have no inherent semantics by themselves, – with schemas which contain components that have semantics only in the context of an <include>ing schema, – when you don’t want to hardcode a namespace to a schema, rather you want <include>ing schemas to be able to provide their own application-specific namespace to the schema Example. A repository of components - such as a schema which defines an array type, or vector, linked list, etc - should be declared with no targetNamespace (i.e., Chameleon). As a rule of thumb, if your schema just contains type definitions (no element declarations) then that schema is probably a good candidate for being a Chameleon schema. Use the Homogeneous Namespace Design • when all of your schemas are conceptually related • when there is no need to visually identify in instance documents the origin/lineage of each element/attribute. In this design all components come from the same namespace, so you loose the ability to identify in instance documents that “element A comes from schema X”. Oftentimes that’s okay - you don’t want to categorize elements/attributes differently. This design approach is well suited for those situations. Use the Heterogeneous Namespace Design • when there are multiple elements with the same name. (Avoid name collision) • when there is a need to visually identify in instance documents the origin/lineage of each element/attribute. In this design the components come from different namespaces, so you have the ability to identify in instance documents that “element A comes from schema X”. Lastly, as we have seen, in a schema each component can be uniquely identified with an id attribute (this is NOT the same as providing an id attribute on an element in instance documents. We are talking here about a schema-internal way of identifying each schema component.) Consider identifying each schema component using the id attribute. This will enable a finer degree of traceability than is possible using namespaces. The combination of namespaces plus the schema id attribute is a powerful tandem for visually and programmatically identifying components. 44