xml| name Space
XML namespaces provide a way to avoid element name collisions.
b> Name conflict
Because the element names in XML are not fixed, a name conflict occurs when two different documents describe two different types of elements using the same name.
The following XML document carries information in a table:
< table>
< tr>
< td>apples</td>
< td>bananas</td>
</tr>
</table>
The following XML document carries information about a table (information about a piece of furniture):
< table>
< Name>african Coffee table</name>
< width>80</width>
< length>120</length>
</table>
If these two XML documents are added together, an element name conflict occurs because both documents contain a < table> element, and the contents and definitions of these two elements are different.
B> to resolve a name conflict with a prefix
The following XML document carries information in a table:
< h:table>
< h:tr>
< h:td>apples< h:td>bananas
And this XML document carries a piece of furniture information:
< f:table>
< F:name>african Coffee table</f:name>
< f:width>80</f:width>
< f:length>120</f:length>
</f:table>
There is no problem with element name conflicts, because two documents use different names for their < table> elements: (< h:table> and < f:table>). By using a prefix, we created two different types of < table> elements.
B> using the name space
The following XML document carries information in a table:
< h:table xmlns:h= "http://www.w3.org/TR/html4/" >
< h:tr>
< h:td>apples< h:td>bananas
This XML document carries information about a piece of furniture:
< f:table xmlns:f= "Http://www.w3schools.com/furniture" >
< F:name>african Coffee table</f:name>
< f:width>80</f:width>
< f:length>120</f:length>
</f:table>
Instead of using only prefixes, an xmlns attribute is added to the < table> tag, which gives the element prefix a qualified name that is associated with the namespace.
b> Name space attribute
The namespace attribute is placed in the start tag of an element, and its syntax is as follows:
Xmlns:namespace-prefix= "Namespace"
In the example above, the namespace itself is defined with an Internet address:
xmlns:f= "Http://www.w3schools.com/furniture" >
The common name Space specification stipulates that the namespace itself should be a Uniform Resource identification number (URI). When a namespace is defined in the start tag of an element, all child elements with the same prefix are associated with the same namespace. Note: The factorization does not use the address used to identify namespaces to find information. The only purpose of this address is to give the name space a unique name. However, companies often use namespaces as a pointer to the actual Web page that contains the name space information. Visit http://www.w3.org/TR/html4/for a try.
B> Unified Resource Identification number
A Uniform Resource identification number (URI) is a string that identifies an Internet resource. Typically, a URI is a URL that identifies an Internet domain address. In addition, there are a few types of URIs that are generic resource names (urns). Only URLs are used in our example. Since we use an Internet address to identify the name space in the example of our furniture, we can be sure that our namespaces are unique.