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 HtlmMaria S Rivera
 
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 ScriptFahim Abdullah
 
Ifi7174 lesson2
Ifi7174 lesson2Ifi7174 lesson2
Ifi7174 lesson2Sónia
 
Ifi7174 lesson1
Ifi7174 lesson1Ifi7174 lesson1
Ifi7174 lesson1Sónia
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS Dave Kelly
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssTesfaye Yenealem
 
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 SemanticsAdrian Roselli
 
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)Patrick Mooney
 
Front-End Methodologies
Front-End MethodologiesFront-End Methodologies
Front-End MethodologiesArash Manteghi
 
HTML 5 Simple Tutorial Part 1
HTML 5 Simple Tutorial Part 1HTML 5 Simple Tutorial Part 1
HTML 5 Simple Tutorial Part 1Sanjeev Kumar
 
Supercharged HTML & CSS
Supercharged HTML & CSSSupercharged HTML & CSS
Supercharged HTML & CSSMax Kraszewski
 
Couch Db.0.9.0.Pub
Couch Db.0.9.0.PubCouch Db.0.9.0.Pub
Couch Db.0.9.0.PubYohei Sasaki
 
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 javascriptMarc Huang
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksAmit Tyagi
 
Internet programming lab manual
Internet programming lab manualInternet programming lab manual
Internet programming lab manualinteldualcore
 
HTML Foundations, pt 2
HTML Foundations, pt 2HTML Foundations, pt 2
HTML Foundations, pt 2Shawn Calvert
 

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

Interim Management En Marketing
Interim Management En MarketingInterim Management En Marketing
Interim Management En MarketingPau Jane
 
Hibernate Shards
Hibernate ShardsHibernate Shards
Hibernate Shardshielkehoeve
 
Java Play RESTful ebean
Java Play RESTful ebeanJava Play RESTful ebean
Java Play RESTful ebeanFaren faren
 
Global Vision Identity
Global Vision Identity Global Vision Identity
Global Vision Identity globalvision
 

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 ExposeLiquidHub
 
Global Versus Local
Global Versus LocalGlobal Versus Local
Global Versus LocalLiquidHub
 
Extending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorExtending MySQL Enterprise Monitor
Extending MySQL Enterprise MonitorMark Leith
 
Debugging and Error handling
Debugging and Error handlingDebugging and Error handling
Debugging and Error handlingSuite Solutions
 
Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Inroduction to XSLT with PHP4
Inroduction to XSLT with PHP4Stephan Schmidt
 
3 xml namespaces and xml schema
3   xml namespaces and xml schema3   xml namespaces and xml schema
3 xml namespaces and xml schemagauravashq
 
Expanding a tree node
Expanding a tree nodeExpanding a tree node
Expanding a tree nodeHemakumar.S
 
Default Namespace
Default NamespaceDefault Namespace
Default NamespaceLiquidHub
 
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 prazosIgor Sobreira
 
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 ToolsCardinaleWay Mazda
 
Dax Declarative Api For Xml
Dax   Declarative Api For XmlDax   Declarative Api For Xml
Dax Declarative Api For XmlLars Trieloff
 
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 MobileChris Toohey
 
XML Business Rules Validation with Schematron
XML Business Rules Validation with SchematronXML Business Rules Validation with Schematron
XML Business Rules Validation with SchematronEmiel Paasschens
 
Nanoformats
NanoformatsNanoformats
Nanoformatsrozario
 

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
 
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
 
XML Business Rules Validation with Schematron
XML Business Rules Validation with SchematronXML Business Rules Validation with Schematron
XML Business Rules Validation with Schematron
 
Schematron
SchematronSchematron
Schematron
 
Nanoformats
NanoformatsNanoformats
Nanoformats
 

More from LiquidHub

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.0LiquidHub
 
Sharepoint 2013 upgrade process
Sharepoint 2013 upgrade processSharepoint 2013 upgrade process
Sharepoint 2013 upgrade processLiquidHub
 
Share point 2013
Share point 2013Share point 2013
Share point 2013LiquidHub
 
Share point 2010-uiimprovements
Share point 2010-uiimprovementsShare point 2010-uiimprovements
Share point 2010-uiimprovementsLiquidHub
 
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-2LiquidHub
 
Managing metadata in_share_point_2010
Managing metadata in_share_point_2010Managing metadata in_share_point_2010
Managing metadata in_share_point_2010LiquidHub
 
Fast search for share point
Fast search for share pointFast search for share point
Fast search for share pointLiquidHub
 
Simple Farm Server Deployment
Simple Farm Server DeploymentSimple Farm Server Deployment
Simple Farm Server DeploymentLiquidHub
 
Pre Install Databases
Pre Install DatabasesPre Install Databases
Pre Install DatabasesLiquidHub
 
Moss 2007 Deployment Detail
Moss 2007 Deployment DetailMoss 2007 Deployment Detail
Moss 2007 Deployment DetailLiquidHub
 
Moss 2007 Backup Strategies
Moss 2007 Backup StrategiesMoss 2007 Backup Strategies
Moss 2007 Backup StrategiesLiquidHub
 
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 2003LiquidHub
 
5060 A 01 Demonstration Steps
5060 A 01 Demonstration Steps5060 A 01 Demonstration Steps
5060 A 01 Demonstration StepsLiquidHub
 
Working With Infopath 2007
Working With Infopath 2007Working With Infopath 2007
Working With Infopath 2007LiquidHub
 
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 WalkthroughLiquidHub
 
Overviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshOverviewofthe2007 Microsoft Office System Components Refresh
Overviewofthe2007 Microsoft Office System Components RefreshLiquidHub
 
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 RefreshLiquidHub
 

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

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Recently uploaded (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

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