SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
Default Namespace - targetNamespace or
                    XMLSchema?
Table of Contents
               Issue
               Introduction
               Approach 1: Default XMLSchema, Qualify targetNamespace
               Approach 2: Qualify XMLSchema, Default targetNamespace
               Approach 3: No Default Namespace - Qualify both XMLSchema and
               targetNamespace
               Best Practice

Issue
When creating a schema should XMLSchema (i.e., http://www.w3.org/2001/XMLSchema) be the
default namespace, or should the targetNamespace be the default, or should there be no default
namespace?

Introduction
Except for no-namespace schemas, every XML Schema uses at least two namespaces - the
targetNamespace and the XMLSchema (http://www.w3.org/2001/XMLSchema) namespace, e.g.,


                                                           http://www.publishing.org (targetNamespace)
            http://www.w3.org/2001/XMLSchema


                             complexType
                                                                   Library
                  element
                              annotation                                     BookCatalogue
                  documentation
                                     integer
                                                                     CardCatalogueEntry
                              sequence
                  string
                                                                      Book
                            schema




                                                                     This schema is comprised
                                                                     of components from two
                                                                     namespaces. Which
                                               Library.xsd
                                                                     namespace should be
                                                                     the default?




                                                       4
There are three ways to design your schemas, with regards to dealing with these two namespaces:
1. Make XMLSchema the default namespace, and explicitly qualify all references to components
   in the targetNamespace.
2. Vice versa - make the targetNamespace the default namespace, and explicitly qualify all
   components from the XMLSchema namespace.
3. Do not use a default namespace - explicitly qualify references to components in the
   targetNamespace and explicitly qualify all components from the XMLSchema namespace.
Let’s look at each approach in detail. In the following discussions we will consider this scenario:



                                                    Declare an element quot;Bookquot;
                                                    globally so that it can be
  The BookCatalogue schema must                     reused by other schemas,
  either:
                                                    e.g., the Library schema
  - have the same namespace as
                                                    BookCatalogue.xsd
    the Library schema, or
  - have no namespace.




                                             targetNamespace=quot;http://www.publishing.orgquot;
                                             include BookCatalogue.xsd
                                             …
                                             quot;refquot; the Book element in BookCatalogue

                                                             Library.xsd




                                                5
Approach 1: Default XMLSchema, Qualify targetNamespace
Below is a Library schema which demonstrates this design approach. It <include>s a
BookCatalogue schema, which contains a declaration for a Book element. The Library schema
references (“ref”s) the Book element.


    <?xml version=quot;1.0quot;?>
    <schema xmlns=quot;http://www.w3.org/2001/XMLSchemaquot;        Default namespace is XMLSchema
             targetNamespace=quot;http://www.library.orgquot;
             xmlns:lib=quot;http://www.library.orgquot;             Set quot;libquot; to point to the targetNamespace
             elementFormDefault=quot;qualifiedquot;>
      <include schemaLocation=quot;BookCatalogue.xsdquot;/>
      <element name=quot;Libraryquot;>
         <complexType>
            <sequence>
              <element name=quot;BookCataloguequot;>
                 <complexType>
                   <sequence>
                     <element ref=quot;lib:Bookquot;                 Qualify the reference to Book
                                maxOccurs=quot;unboundedquot;/>
                   </sequence>
                 </complexType>
              </element>
           </sequence>
         </complexType>
      </element>
    </schema>



Note that XMLSchema is the default namespace. Consequently, all the components used to
construct the schema - element, include, complexType, sequence, schema, etc - have no
namespace qualifier on them.

There is a namespace prefix, lib, which is associated with the targetNamespace. Any references
(using the “ref” attribute) to components in the targetNamespace (Library, BookCatalogue,
Book, etc) are explicitly qualified with lib (in this example there is a ref to lib:Book).

Advantages:
If your schema is referencing components from multiple namespaces then this approach gives a
consistent way of referring to the components (i.e., you always qualify the reference).

Disadvantages:
Schemas which have no-targetNamespace must be designed so that the XMLSchema
components (element, complexType, sequence, etc) are qualified. If you adopt this approach to
designing your schemas then in some of your schemas you will qualify the XMLSchema
components and in other schemas you won’t qualify the XMLSchema components. Changing
from one way of designing your schemas to another way can be confusing.




                                                     6
Approach 2: Qualify XMLSchema, Default targetNamespace
This design approach is the mirror image of the first approach:



 <?xml version=quot;1.0quot;?>
 <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;     Set quot;xsdquot; to point to the XMLSchema
               targetNamespace=quot;http://www.library.orgquot;       namespace
              xmlns=quot;http://www.library.orgquot;
              elementFormDefault=quot;qualifiedquot;>
   <xsd:include schemaLocation=quot;BookCatalogue.xsdquot;/>              Default namespace is targetNamespace
   <xsd:element name=quot;Libraryquot;>
      <xsd:complexType>
         <xsd:sequence>
           <xsd:element name=quot;BookCataloguequot;>
              <xsd:complexType>
                 <xsd:sequence>
                   <xsd:element ref=quot;Bookquot;                        Book is in the default namespace (thus,
                                                                  no namespace qualifier required)
                                 maxOccurs=quot;unboundedquot;/>
                 </xsd:sequence>
              </xsd:complexType>
           </xsd:element>
        </xsd:sequence>                                      Qualify the XMLSchema components
      </xsd:complexType>                                     (schema, include, element, complexType,
   </xsd:element>                                            sequence)
 </xsd:schema>



With this approach all the components used to construct a schema are namespace qualified (with
xsd:).

There is a default namespace declaration that declares the targetNamespace to be the default
namespace. Any references to components in the targetNamespace are not namespace qualified
(note that the ref to Book is not namespace qualified).

Advantages:
Schemas which have no-targetNamespace must be designed so that the XMLSchema
components (element, complexType, sequence, etc) are qualified. This approach will work
whether your schema has a targetNamespace or not. Thus, with this approach you have a
consistent approach to designing your schemas - always namespace-qualify the XMLSchema
components.

Disadvantages:
If your schema is referencing components from multiple namespaces then for some references
you will namespace-qualify the reference, whereas other times you will not (i.e., when you are
referencing components in the targetNamespace). This variable use of namespace qualifiers in
referencing components can be confusing.



                                                7
Approach 3: No Default Namespace - Qualify both XMLSchema and
targetNamespace
This design approach does not have a default namespace:



 <?xml version=quot;1.0quot;?>
 <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot;         Set quot;xsdquot; to point to the XMLSchema
               targetNamespace=quot;http://www.library.orgquot;           namespace
              xmlns:lib=quot;http://www.library.orgquot;
              elementFormDefault=quot;qualifiedquot;>                      Set quot;libquot; to point to the targetNamespace
   <xsd:include schemaLocation=quot;BookCatalogue.xsdquot;/>
   <xsd:element name=quot;Libraryquot;>
      <xsd:complexType>
         <xsd:sequence>
           <xsd:element name=quot;BookCataloguequot;>
              <xsd:complexType>
                 <xsd:sequence>
                   <xsd:element ref=quot;lib:Bookquot;                      Qualify the reference to Book
                                maxOccurs=quot;unboundedquot;/>
                 </xsd:sequence>
              </xsd:complexType>
           </xsd:element>
        </xsd:sequence>                                          Qualify the XMLSchema components
      </xsd:complexType>                                         (schema, include, element, complexType,
   </xsd:element>                                                sequence)
 </xsd:schema>



Note that both the XMLSchema components are explicitly qualified, as well as are references to
components in the targetNamespace.

Advantages:
[1] Schemas which have no-targetNamespace must be designed so that the XMLSchema
    components (element, complexType, sequence, etc) are qualified. With this approach all
    your schemas are designed in a consistent fashion.
[2] If your schema is referencing components from multiple namespaces then this approach
    gives a consistent way of referencing components (i.e., you always qualify the reference).
Disadvantages:
Very cluttered: being very explicit by namespace qualifying all components and all references
can be annoying when reading the schema.
Best Practice
There is no clear-cut best practice with regards to this issue. In large part it is a matter of
personal preference.




                                                   8

Contenu connexe

Tendances

Tendances (11)

SynapseIndia dotnet client library Development
SynapseIndia dotnet client library DevelopmentSynapseIndia dotnet client library Development
SynapseIndia dotnet client library Development
 
26xslt
26xslt26xslt
26xslt
 
JAXP
JAXPJAXP
JAXP
 
Solr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approachSolr Troubleshooting - TreeMap approach
Solr Troubleshooting - TreeMap approach
 
Tool Development 04 - XML
Tool Development 04 - XMLTool Development 04 - XML
Tool Development 04 - XML
 
Tool Development 05 - XML Schema, INI, JSON, YAML
Tool Development 05 - XML Schema, INI, JSON, YAMLTool Development 05 - XML Schema, INI, JSON, YAML
Tool Development 05 - XML Schema, INI, JSON, YAML
 
Pxb For Yapc2008
Pxb For Yapc2008Pxb For Yapc2008
Pxb For Yapc2008
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
 
Parsing XML Data
Parsing XML DataParsing XML Data
Parsing XML Data
 
6 xml parsing
6   xml parsing6   xml parsing
6 xml parsing
 
Solr Masterclass Bangkok, June 2014
Solr Masterclass Bangkok, June 2014Solr Masterclass Bangkok, June 2014
Solr Masterclass Bangkok, June 2014
 

Similaire à Default Namespace

Global Versus Local
Global Versus LocalGlobal Versus Local
Global Versus Local
LiquidHub
 
Zero One Or Many Namespaces
Zero One Or Many NamespacesZero One Or Many Namespaces
Zero One Or Many Namespaces
LiquidHub
 
Using elasticsearch with rails
Using elasticsearch with railsUsing elasticsearch with rails
Using elasticsearch with rails
Tom Z Zeng
 

Similaire à Default Namespace (20)

Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)Native XML processing in C++ (BoostCon'11)
Native XML processing in C++ (BoostCon'11)
 
XML
XMLXML
XML
 
Global Versus Local
Global Versus LocalGlobal Versus Local
Global Versus Local
 
Zero One Or Many Namespaces
Zero One Or Many NamespacesZero One Or Many Namespaces
Zero One Or Many Namespaces
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
Xml processing in scala
Xml processing in scalaXml processing in scala
Xml processing in scala
 
XML Bible
XML BibleXML Bible
XML Bible
 
A Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaA Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to Scala
 
Ch23
Ch23Ch23
Ch23
 
Ch23 xml processing_with_java
Ch23 xml processing_with_javaCh23 xml processing_with_java
Ch23 xml processing_with_java
 
Soap2
Soap2Soap2
Soap2
 
24sax
24sax24sax
24sax
 
XMl
XMlXMl
XMl
 
DOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om SivanesianDOSUG XML Beans overview by Om Sivanesian
DOSUG XML Beans overview by Om Sivanesian
 
Xml part4
Xml part4Xml part4
Xml part4
 
Compass Framework
Compass FrameworkCompass Framework
Compass Framework
 
xml2tex at TUG 2014
xml2tex at TUG 2014xml2tex at TUG 2014
xml2tex at TUG 2014
 
Javasession6
Javasession6Javasession6
Javasession6
 
Spark sql
Spark sqlSpark sql
Spark sql
 
Using elasticsearch with rails
Using elasticsearch with railsUsing elasticsearch with rails
Using elasticsearch with rails
 

Plus de 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
 

Plus de 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
 

Dernier

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
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)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Default Namespace

  • 1. Default Namespace - targetNamespace or XMLSchema? Table of Contents Issue Introduction Approach 1: Default XMLSchema, Qualify targetNamespace Approach 2: Qualify XMLSchema, Default targetNamespace Approach 3: No Default Namespace - Qualify both XMLSchema and targetNamespace Best Practice Issue When creating a schema should XMLSchema (i.e., http://www.w3.org/2001/XMLSchema) be the default namespace, or should the targetNamespace be the default, or should there be no default namespace? Introduction Except for no-namespace schemas, every XML Schema uses at least two namespaces - the targetNamespace and the XMLSchema (http://www.w3.org/2001/XMLSchema) namespace, e.g., http://www.publishing.org (targetNamespace) http://www.w3.org/2001/XMLSchema complexType Library element annotation BookCatalogue documentation integer CardCatalogueEntry sequence string Book schema This schema is comprised of components from two namespaces. Which Library.xsd namespace should be the default? 4
  • 2. There are three ways to design your schemas, with regards to dealing with these two namespaces: 1. Make XMLSchema the default namespace, and explicitly qualify all references to components in the targetNamespace. 2. Vice versa - make the targetNamespace the default namespace, and explicitly qualify all components from the XMLSchema namespace. 3. Do not use a default namespace - explicitly qualify references to components in the targetNamespace and explicitly qualify all components from the XMLSchema namespace. Let’s look at each approach in detail. In the following discussions we will consider this scenario: Declare an element quot;Bookquot; globally so that it can be The BookCatalogue schema must reused by other schemas, either: e.g., the Library schema - have the same namespace as BookCatalogue.xsd the Library schema, or - have no namespace. targetNamespace=quot;http://www.publishing.orgquot; include BookCatalogue.xsd … quot;refquot; the Book element in BookCatalogue Library.xsd 5
  • 3. Approach 1: Default XMLSchema, Qualify targetNamespace Below is a Library schema which demonstrates this design approach. It <include>s a BookCatalogue schema, which contains a declaration for a Book element. The Library schema references (“ref”s) the Book element. <?xml version=quot;1.0quot;?> <schema xmlns=quot;http://www.w3.org/2001/XMLSchemaquot; Default namespace is XMLSchema targetNamespace=quot;http://www.library.orgquot; xmlns:lib=quot;http://www.library.orgquot; Set quot;libquot; to point to the targetNamespace elementFormDefault=quot;qualifiedquot;> <include schemaLocation=quot;BookCatalogue.xsdquot;/> <element name=quot;Libraryquot;> <complexType> <sequence> <element name=quot;BookCataloguequot;> <complexType> <sequence> <element ref=quot;lib:Bookquot; Qualify the reference to Book maxOccurs=quot;unboundedquot;/> </sequence> </complexType> </element> </sequence> </complexType> </element> </schema> Note that XMLSchema is the default namespace. Consequently, all the components used to construct the schema - element, include, complexType, sequence, schema, etc - have no namespace qualifier on them. There is a namespace prefix, lib, which is associated with the targetNamespace. Any references (using the “ref” attribute) to components in the targetNamespace (Library, BookCatalogue, Book, etc) are explicitly qualified with lib (in this example there is a ref to lib:Book). Advantages: If your schema is referencing components from multiple namespaces then this approach gives a consistent way of referring to the components (i.e., you always qualify the reference). Disadvantages: Schemas which have no-targetNamespace must be designed so that the XMLSchema components (element, complexType, sequence, etc) are qualified. If you adopt this approach to designing your schemas then in some of your schemas you will qualify the XMLSchema components and in other schemas you won’t qualify the XMLSchema components. Changing from one way of designing your schemas to another way can be confusing. 6
  • 4. Approach 2: Qualify XMLSchema, Default targetNamespace This design approach is the mirror image of the first approach: <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; Set quot;xsdquot; to point to the XMLSchema targetNamespace=quot;http://www.library.orgquot; namespace xmlns=quot;http://www.library.orgquot; elementFormDefault=quot;qualifiedquot;> <xsd:include schemaLocation=quot;BookCatalogue.xsdquot;/> Default namespace is targetNamespace <xsd:element name=quot;Libraryquot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;BookCataloguequot;> <xsd:complexType> <xsd:sequence> <xsd:element ref=quot;Bookquot; Book is in the default namespace (thus, no namespace qualifier required) maxOccurs=quot;unboundedquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> Qualify the XMLSchema components </xsd:complexType> (schema, include, element, complexType, </xsd:element> sequence) </xsd:schema> With this approach all the components used to construct a schema are namespace qualified (with xsd:). There is a default namespace declaration that declares the targetNamespace to be the default namespace. Any references to components in the targetNamespace are not namespace qualified (note that the ref to Book is not namespace qualified). Advantages: Schemas which have no-targetNamespace must be designed so that the XMLSchema components (element, complexType, sequence, etc) are qualified. This approach will work whether your schema has a targetNamespace or not. Thus, with this approach you have a consistent approach to designing your schemas - always namespace-qualify the XMLSchema components. Disadvantages: If your schema is referencing components from multiple namespaces then for some references you will namespace-qualify the reference, whereas other times you will not (i.e., when you are referencing components in the targetNamespace). This variable use of namespace qualifiers in referencing components can be confusing. 7
  • 5. Approach 3: No Default Namespace - Qualify both XMLSchema and targetNamespace This design approach does not have a default namespace: <?xml version=quot;1.0quot;?> <xsd:schema xmlns:xsd=quot;http://www.w3.org/2001/XMLSchemaquot; Set quot;xsdquot; to point to the XMLSchema targetNamespace=quot;http://www.library.orgquot; namespace xmlns:lib=quot;http://www.library.orgquot; elementFormDefault=quot;qualifiedquot;> Set quot;libquot; to point to the targetNamespace <xsd:include schemaLocation=quot;BookCatalogue.xsdquot;/> <xsd:element name=quot;Libraryquot;> <xsd:complexType> <xsd:sequence> <xsd:element name=quot;BookCataloguequot;> <xsd:complexType> <xsd:sequence> <xsd:element ref=quot;lib:Bookquot; Qualify the reference to Book maxOccurs=quot;unboundedquot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> Qualify the XMLSchema components </xsd:complexType> (schema, include, element, complexType, </xsd:element> sequence) </xsd:schema> Note that both the XMLSchema components are explicitly qualified, as well as are references to components in the targetNamespace. Advantages: [1] Schemas which have no-targetNamespace must be designed so that the XMLSchema components (element, complexType, sequence, etc) are qualified. With this approach all your schemas are designed in a consistent fashion. [2] If your schema is referencing components from multiple namespaces then this approach gives a consistent way of referencing components (i.e., you always qualify the reference). Disadvantages: Very cluttered: being very explicit by namespace qualifying all components and all references can be annoying when reading the schema. Best Practice There is no clear-cut best practice with regards to this issue. In large part it is a matter of personal preference. 8