Namespaces can be used to qualify names. If an XML document was created from multiple sources, then some of the elements may have the same names. If the XML document will be used in a basically self-contained environment, then a name space will not be necessary. See also W3C for Namespaces in XML [§].

There are four scopes for namespaces:

<?xml version="1.0"?>
<?xml:namespace ns="http://www.yoursite.com/ns1" prefix="ns1"?>
<ns1:myrootnode>
	<ns1:child>
		This child belongs to the document namespace
	</ns1:child>
	<ns2:child xmlns:ns2="http://www.yoursite.com/ns2">
		This child does not belong to the document namespace,
		it belongs to an explicit namespace.
		<ns1:gChild>
			This gchild belongs to the doc ns.
		<ns1:gChild>
		<ns2:gChild>
			This gchild belongs to the explicit ns.
		<ns2:gChild>
		<gChild>
			This gchild is of local scope.
		<gChild>
	</ns2:child>
	<child xmlns="http://www.yoursite.com/ns3">
		This child does not belong to the document namespace,
		it belongs to a default namespace.
		<ns1:gChild>
			This gchild belongs to the doc ns.
		<ns1:gChild>
		<gChild>
			This gchild belongs to the default local scope.
			It does not belong to a local scope.
		<gChild>
	<child>
	<child>
		This child does not belong to any namespace,
		it is of local scope.
	</child>
</ns1:myrootnode>

Note that the URI that a namespace points to does not necessarily have to point to a real document such as an XML Schema. All that counts is that the namespace is is unique on the Internet.

Page Modified: (Hand noted: ) (Auto noted: )