XML NAMESPACES Using XML to define your organization's business data and process information can be very difficult when you have overlapping departments and redundant data definitions. Having two XML elements called CustomerInformation can be detrimental to your XML implementation if the two elements are not identical. XML namespaces can help resolve conflicts between element names. OVERVIEW The basic problem that namespaces solve is collision between identically named elements. A namespace is a set of names that exist within a particular domain, the namespace. A good analogy is shoe sizes. A size nine is not always a size nine. Not because different makers have different tolerances, but because a women's size nine is not the same as a men's size nine. These sizes exist in two different domains: women's and men's. These domains are analogous to namespaces. The reason that XML namespaces exist is to help identify and resolve conflicts between elements that have the same name but mean different things. This situation can occur when elements from different DTDs are included in the same XML document. In this scenario, each DTD would maintain it's own unique XML namespace, and the resulting XML document would refer to its elements in the context of which namespace they belong. HOW THEY WORK Namespaces are identified within the XML document where they are used. An XML document may use multiple namespaces simultaneously. Each namespace is identified using a Unified Resource Identifier (URI). The URI points to an external file that defines the particular namespace being used. In addition to identifying the namespace resource, the XML document may assign a variable name to the particular namespace that will be used in element names to identify to which namespace they belong. The following example illustrates how multiple namespaces might be defined in an XML document: 990023 9902 Broadway Chicago IL 60612 In this example, two namespaces have been declared. The first one refers to the customers namespace and indicates that elements and attributes in the customers namespace will be prefixed by the tag cust. The second one refers to the address namespace that is identified by the addr prefix. DEFAULT NAMESPACE In addition to declaring namespaces identified with a prefix, you have the option of declaring a default namespace. The default namespace handles the names of elements and attributes that do not contain a namespace prefix. The following example illustrates the use of both a default namespace and a named namespace: Joe's Corp. 99123 Widget Bracket 344-34-599834 12 233.50 In this example, you can see that both the and elements have been used more than once. Because the default namespace has been declared as the orders namespace, the orders elements do not require a prefix. Thus the elements and in the element refer to the orders definition of an item name and item number. The and elements above refer to the customers namespace definition of a customer name and customer number. SUMMARY Creating XML documents and specifications that don't use overlapping or duplicate names can be a difficult task. This undertaking can be complicated even more when documents from multiple organizations are brought together. Using XML namespaces can help alleviate issues where XML elements and attributes use identical names.