Java XML - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Java XML Namespace

Java XML Namespace

shape Description

A Namespace is a plan of extraordinary names. A namespace is a segment by which segment and trademark name can be dispensed to the specific gathering. The Namespace is perceived by URI. A XML namespace is proclaimed using the saved properties and name must be started with "xmlns". The accompanying is the statement of the namespace. [xml]<element xmlns:name="URL">[/xml] The following is the syntax description image.

shape Example

The following is an example. [xml]<?xml version="1.0" encoding="UTF-8"?> <cont:contact xmlns:cont="http://sssit.org/contact-us"> <cont:name>Albert</cont:name> <cont:company>SSSIT.org</cont:company> <cont:phone>(040) 524-4646</cont:phone> </cont:contact>[/xml] Where cont is the Namespace Prefix and http://sssit.org/contact-us is the namespace identifier. For the most part, in XML, components name are characterized by the engineer so there is an opportunity to conflict in name of the components. To evade these sorts of confliction the developer utilize XML Namespaces. The developer can say that XML Namespaces give a technique to avoid conflict of the name. These conflicts happen when the developer attempt to blend XML archives from various XML application. The following is an example. Following is the first table code. [xml] <table> <tr> <td>Aries</td> <td>Bingo</td> </tr> </table> [/xml] Following is the second table code. [xml] <table> <name>Computer table</name> <width>80</width> <length>120</length> </table> [/xml] In the event that both cases are blended, there would be a name struggle in light of the fact that both have component. In spite of the fact that they have distinctive name and importance.

Rid of name conflict

shape Description

The developer can get rid of name conflict in two ways as follows.

By Using a Prefix

Following is an example to understand the code. [xml]<h:table> <h:tr> <h:td>Aries</h:td> <h:td>Bingo</h:td> </h:tr> </h:table> <f:table> <f:name>Computer table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table>[/xml] In the above code, conflict won't be raised on the grounds that both the tables have particular names.

By Using xmlns Attribute

The following is the code by using xmlns attribute. [xml] <root> <h:table xmlns:h="http://www.abc.com/TR/html4/"> <h:tr> <h:td>Aries</h:td> <h:td>Bingo</h:td> </h:tr> </h:table> <f:table xmlns:f="http://www.xyz.com/furniture"> <f:name>Computer table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> [/xml] In the above code, the component characterizes a namespace and when a namespace is characterized by a component, the child components with the same prefixes are connected with the same namespace.

URI And Default Namespace

shape Description

Uniform Resource Identifier is utilized to recognize the web asset and is a series of characters. The most well-known URI is URL (Uniform Resource Locator) which recognizes a web space address. There is additionally a URI name URN (Universal Resource Name) yet it is not all that normal. The default namespace is utilized as a part of the XML report to spare you from utilizing prefixes as a part of all the tyke elements. The just distinction between default namespace and a straightforward namespace is that: There is no compelling reason to utilize a prefix in the default namespace. Following is an example for the default namespace. [xml]<tutorials xmlns="http://www.splessons.com/java-tutorial"> <tutorial> <title>Java-tutorial</title> <author>xxxx</author> </tutorial> ... </tutorials>[/xml] The engineer can likewise utilize numerous namespaces inside a similar report simply characterize a namespace against a child hub.

Summary

shape Key Points

  • URI stands for uniform resoure identifier.
  • Namespace influences just a constrained territory in the archive.
  • Namespace is utilized to evade component name conflict in XML archive.