The best XML Namespaces Tutorial In 2024, In this tutorial you can learn Naming conflicts,Use prefixes to avoid naming conflicts,XML namespace - xmlns attribute,Uniform resource identifier (URI, stands for Uniform Resource Identifier),Default namespace,Actual use of the namespace,
XML Namespaces provide a method to avoid element name conflicts.
In XML, element names are defined by the developer, when two different documents use the same element name, a naming conflict will occur.
This XML carries HTML table information:
This XML carries information about a table (a piece of furniture):
If these two XML documents are used together, since the two documents are included with different content and definition of the <table> element, naming conflicts occur.
XML parser can not determine how to deal with such conflicts.
Naming conflicts in XML can be obtained by using the name prefix so easily avoided.
This XML carries HTML table and a piece of furniture in a message:
In the example above, there is no conflict because the two <table> elements have different names.
When using prefixes in XML, a so-callednamespace for the prefix must be defined.
Namespacexmlns attribute is defined in the start tag of the element.
Namespace declaration syntax is as follows. xmlns:prefix= "URI".
In the example above, xmlns attribute <table> tag defines h: namespace prefix qualified: and f.
When a namespace is defined in the start tag of the element, all child elements with the same prefix and are associated with a namespace.
Namespace, you can declare or they are used in the element in the XML root element:
Note: The namespace URI parser will not be used to find information.
Its purpose is to give the namespace a unique name. However, many companies often use the namespace as a pointer to point to the actual existence of a page, this page contains information about the namespace.
Visit http://www.w3.org/TR/html4/ .
Uniform Resource Identifier (URI) is a string of characters that may identify Internet resources.
The most common URI is theUniform Resource Locator used to identify an Internet domain address (URL).A less common URI is theUniform Resource Name (URN).
In our example, we only use URL.
Element defines the default namespace allows us to omit the prefix in all the sub-elements in the work. Its syntax is as follows:
This XML carries HTML table information:
This XML carries information about a piece of furniture:
XSLT is a process for the XML documents into other XML language format, such as HTML.
In the XSLT document below, you can see that most of the tags are HTML tags.
Non-HTML tags have the prefix xsl, and thus identifies the namespace: xmlns: xsl = "#":
If you want to learn about XSLT, please our home page to find XSLT tutorial.