Defining Namespaces

The Namespaces in XML Recommendation did not provide syntax for defining what’s in a namespace. In many situations, this type of syntactic definition is not even necessary. Today, most XML namespaces are defined in formal specification documents that describe the names of elements as well as attributes along with their semantics. This is exactly how all of the W3C namespaces are formally defined (see the XSLT 1.0 specification at http://www.w3.org/TR/xslt for an example).

Once a namespace has been defined, software developers implement the namespace as outlined by the specification. For example, MSXML 3.0, Xalan, and Saxon are all implementations of the XSLT 1.0 specification. These implementations are hardcoded to look for elements that belong to the XSLT 1.0 namespace (http://www.w3.org/1999/XSL/Transform). To use these implementations, you need to feed them an XML document that uses the names from the XSLT 1.0 namespace correctly (more on this in the next section). If anything in the XSLT 1.0 namespace were to change, the supporting software would have to be updated.

The XML Schema working group (http://www.w3.org/XML/Schema) has put together a new specification (XML Schema) that defines an XML-based syntax for defining elements, attributes, and types in a namespace. XML Schema finally makes it possible to provide a syntactic definition of a namespace, as illustrated below.

<schema xmlns='http://www.w3.org/2000/10/XMLSchema'
   targetNamespace='http://www.develop.com/student'
   elementFormDefault='qualified'
>
  <element name='student'>
     <complexType>
         <sequence>
            <element name='id' type='long'/>
            <element name='name' type='string'/>
            <element name='language' type='string'/>
            <element name='rating' type='double'/>         
         </sequence>
     </complexType>
   </element>
</schema>

This example defines the namespace http://www.develop.com/student as containing four named elements: student, id, name, language, and rating. Besides just providing a namespace, this schema also provides additional metadata, such as the order of the student child elements as well as their types.

With syntactic namespace definitions like those offered by XML Schema in place, it’s possible to build more sophisticated software that leverages the name and type information at runtime. XML Schemas still don’t define the semantics of the defined elements and attributes and would therefore still require an accompanying specification. In the future, most XML namespaces will be defined through both specifications and schema definitions.

Share this post
[social_warfare]
Namespace
Namespace Prefix

Get industry recognized certification – Contact us

keyboard_arrow_up