Default Namespace

When you use a namespace, you need to append a prefix with each tag in the child elements. To avoid such repetition, you can use a default namespace. You create a default namespace for an XML document using a blank prefix in the declaration of the namespace. The syntax of a default namespace is:

    xmlns=”namespaceURI

The following code snippet shows the declaration of a default namespace:

    <name xmlns="http://myexample.com”>

Note that a prefix name is not specified after the xmlns keyword. If an element is created without a prefix, the default namespace prefixed to the element helps to uniquely identify the element and the child elements. The following code uses the default namespace for elements such as partnername and organizationname:

    <name xmlns=”http://www.mysite.com/partner”>
         <partnername> ABC </partnername>
         <organizationname> XYZ </organizationname>
    </name>

Note that you cannot specify a default namespace for an attribute because an attribute without a prefix does not belong to any namespace.

<!-- Business partner information with namespace declaration -->
<name xmlns=”http://www.mysite.com/partner” >      <partnername> ABC </partnername>       <organizationname> XYZ
      </organizationname>
</name>

Click the Next button to continue.