Introduction to XML Namespaces

The flexibility of XML allows for you to automatically create ways to represent data in a meaningful way. If there is a particular organization or structure of a group of objects or set of data you are trying to represent, you can create the appropriate elements to represent these structures. For example, we might use a <race> element to represent the race of a <person> element. Likewise, we might be storing infomation in the same file about a marathon the <person> has run in a <race> element. This situtation creates some confusion, and is where XML namespaces come in handy.

<person>
  <name>Bob</name>
  <race>Caucasian</race>
  <race>Boston Marathon</race>

</person>

Utilizing namespaces, we can make each race have more meaning.

<person
xmlns:p="http://www.xmlpronews.com/person"
xmlns:r="http://www.xmlpronews.com/race">

  <p:name>Bob</name>
  <p:race>Caucasian</race>
  <r:race>Boston Marathon</race>
</person>

With XML Namespaces declared, a p: element represents something in the namespace described at http://www.xmlpronews.com/person. This file does not actually exist, but, if it did, would simply describe the available elements for the namespace. The W3C XML namespace for HTML4 can be found at http://www.w3.org/TR/html4. There is no required format for these namespace pages.

Michael Marr
About Michael Marr
Michael Marr is a staff writer for WebProNews

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>