XML Namespaces

Namespaces in XML are a means of avoiding tag and attribute name conflicts. Consider an XML standard such as the Dublin Core, whose purpose is to provide a universal set of XML metadata tags such as creator and date that can be incorporated into other XML standards.

But there is a high probability that when incorporating the Dublin Core into another body of XML, a tag such as "date" will already be present. For instance:

<document>
	<author>John Heinstein</author>
	<date>20040227</date>
	<content>Blah blah blah</content>
	<!-- Dublin Core follows -->
	<creator>John Heinstein</creator>
	<date>20040227</date>
</document>

How is an XML processor to tell one date tag from the other? XML Namespaces proposes that to differentiate one tag from another, a prefix can be prepended to the tag name. This prefix is associated with a unique URI (Universal Resource Identifier) called a namespace URI.

So, in the case of the above xml, an XML namespace declaration would be made at the root of the document, and any Dublin Core elements or attributes would be prefixed with "dc":

<document xmlns:dc="http://purl.org/dc/elements/1.1/">
	<author>John Heinstein</author>
	<date>20040227</date>
	<content>Blah blah blah</content>
	<!-- Dublin Core follows -->
	<dc:creator>John Heinstein</dc:creator>
	<dc:date>20040227</dc:date>
</document>

For an excellent description of namespaces, visit Ronald Bourret's XML Namespaces FAQ.

DOMIT! is now capable of handling namespaces. To invoke namespace awareness in DOMIT!, use the setNamespaceAwareness method:

$xmldoc =& new DOMIT_Document();
$xmldoc->setNamespaceAwareness(true);


Documentation generated by ClassyDoc, using the DOMIT! and SAXY parsers.
Please visit Engage Interactive to download free copies.