NamespacesBecause XML is extensible, anybody or any organization can draft its own tags. This raises the risk that two different organizations or people will use the same tag with different meanings. The namespace mechanism is a small extension to XML to clearly label the owner of a tag. The mechanism builds on the familiar URIs (URLs and URNs). For example, the following uses the element title as defined in the context of namespace http://www.psol.com/axs/library. The namespace is declared (with the xmlns attribute) and bound to a prefix ( psol ). <psol:title xmlns:psol="http://www.psol.com/axs/library">Applied XML Solutions</psol: title> Although simple, namespace is the source of much confusion so let's debunk two of the most common errors:
It is probably easier if you forget the prefix and think of the document as <http://www.psol.com/axs/library:title>Applied XML Solutions </http://www.psol.com/ axs/library:title> In practice, however, this would be verbose and the element name would include illegal characters (such as / ). Hence the prefix mechanism. |