Attributes Entitites   «Prev 

Namespace URIs

The URI associated with a namespace does not necessarily contain meaningful content for the definition of the namespace. Thus, a namespace URI that points to
http://www.ucedu.org
cannot be expected to specify a detailed definition of all the elements and attributes that may be used in the ucedu namespace. The URI's purpose is to define a unique, ubiquitously applicable name with the namespace. The key point to remember here is that a namespace is a label and it is not required to access the URI specified to be useful.

Creating Your First Namespace

When creating your first namespace you should use the URI format. The URI must be unique because you do not want it to clash with someone else's URI definition. Since most companies and independent software developers have their own registered domain, it is become fairly standard to use their domain name as a starting point. So your namespace starts with http://www.javadeploy.com. Following the domain name you can use most any combination of characters you want, although you should avoid spaces and the question mark. The definitive list of what is and is not allowed depends on whether you are using XML Namespace version 1.0 or version 1.1

Namespaces and Prefixes

A common way to create a globally unique name is by forming a pair that consists of a namespace prefix[1] and a local name. The namespace prefix uniquely identifies the namespace, the local name must be unique within that namespace, and the combination of the two creates a globally unique name. This is how Java classes and packages operate: the name of a package is globally unique (or at least has a good chance of being so), class names are unique within a package, and a fully qualified class name consists of the package name as a prefix, followed by a period and the class name. Reversed URLs are often used as package names: a good deal of Sun's software is in the com.sun package or its subpackages, for instance:
com.sun.xml.parser.Resolver res = new com.sun.xml.parser.Resolver();

Here, Resolver is a local name, com.sun.xml.parser is both the name of the package and a unique namespace prefix, and the combination of the two is a fully qualified, globally unique name of Sun's Resolver class. The designers of XML Namespaces had a well-known source of globally unique names ready at hand: the URL, or its generalization, the URI. It was a natural decision to make it a source of unique namespace prefixes, so that a unique element name would consist of a URI prefix to identify the namespace and a local name that is unique within that namespace. Conceptually, if our company URL is http://www.n-topus.com, and we want to put our Address element in a protected namespace, we would say that its fully qualified globally unique name is something like {https://www.cplusoop.com/basic-com/module4/add-com-class.php} Address. The problem is that this name, as written, is not a legal XML name, and it is also extremely long. The solution of XML Namespaces is to use a two-step procedure for establishing a namespace. In the first step, a unique namespace URI is declared and mapped to a prefix that contains only legal characters. In the scope of that declaration, the prefix serves as a proxy for the namespace URI. Below is an example:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">

</xsl:template>
</xsl:stylesheet>

The second line of this code contains a namespace declaration that maps the URI to a prefix. The prefix for this particular namespace is usually xsl, but any prefix would do as long as it is associated with the right URI. Syntactically, the declaration is an attribute. The name of the attribute consists of a reserved sequence of characters, xmlns, followed by a colon and the prefix to which the namespace URI is mapped; the value of the attribute is the namespace URI. The scope of the declaration includes the element whose start tag contains that declaration and all the descendants of that element , unless there is another declaration with more local scope, as discussed shortly.

[1] namespace prefix: An attribute-based declaration syntax is provided to bind prefixes to namespace names and to bind a default namespace that applies to unprefixed element names; these declarations are scoped by the elements on which they appear so that different bindings may apply in different parts of a document. Processors conforming to this specification MUST recognize and act on these declarations and prefixes.