XML Namespaces provide a method to avoid element name conflicts.
In XML, element names are defined by the developer. This often results in a conflict when trying
to mix XML documents from different XML applications.
This XML carries HTML table information:
This XML carries information about Bench
If these XML fragments were added together, there would be a name conflict. Both contain a <table>
element, but the elements have different content and meaning.
An XML parser will not know how to handle these differences.
Name conflicts in XML can easily be avoided using a name prefix.
This XML carries information about an HTML table, and a piece of furniture:
In the example above, there will be no conflict because the two <table> elements have
When using prefixes in XML, a so-called namespace for the prefix must be defined.
The namespace is defined by the xmlns attribute in the start tag of an element.
The namespace declaration has the following syntax. xmlns:prefix="URI".
In the example above, the xmlns attribute in the <table> tag give the h: and f: prefixes a
When a namespace is defined for an element, all child elements with the same prefix are
associated with the same namespace.
Namespaces can be declared in the elements where they are used or in the XML root element:
Note: The namespace URI is not used by the parser to look up information.
A Uniform Resource Identifier (URI) is a string of characters which identifies an Internet
The most common URI is the Uniform Resource Locator (URL) which identifies an Internet
domain address. Another, not so common type of URI is the Universal Resource Name (URN).
In our examples we will only use URLs.
Defining a default namespace for an element saves us from using prefixes in all the child
elements. It has the following syntax:
This XML carries information about a piece of furniture:
XSLT is an XML language that can be used to transform XML documents into other formats, like
In the XSLT document below, you can see that most of the tags are HTML tags.
The tags that are not HTML tags have the prefix xsl, identified by the namespace xmlns:xsl="http://www.w3.org/1999/XSL/Transform":
Your Query was successfully sent!