Home

Namespaces

     

Introduction

In all of the XML documents we created so far, we knew all the names of elements we were using and only we were using them. It is typical that someone else would use the same names for another application, probably in the same order of the same arrangements. If an XML document we created had to be used in the same application with another XML document but if both documents use the same names of elements, there would be name conflicts, making it difficult to distinguish what name is used and when. A namespace can be used to solve such a problem.

An XML namespace is a document that makes it possible to distinguish the names of XML elements in a document. This makes it possible that two similar names be used in the same XML document but having different meanings.

The Name of a Namespace

To make a namespace useful, you must create it in a document that defines its members. To specify the location of that document, in the top section of the XML file that will use it, create an XML tag that contains an attribute named xmlns. The formula to follow is:

<Name xmlns="Value"></Name>

Like every XML tag, you start with a name. Like every attribute, the xmlns name must have a value. The value must be the address URL of the document that contains the definition of the namespace. Of course, the tag must be closed. Here is an example:

<a xmlns:='http://some.website.com/'>
</a>

. Here is an example:

<?x

 

 

 

 

     
 

Previous Copyright © 2010-2016, FunctionX Home