Microsoft Office Online
Sign in to My Office Online (What's this?) | Sign in

Warning: You are viewing this page with an unsupported Web browser. This Web site works best with Microsoft Internet Explorer 6.0 or later, Firefox 1.5, or Netscape Navigator 8.0 or later. Learn more about supported browsers.

Email this linkEmail this link Printer-Friendly VersionPrinter-Friendly Version Bookmark and ShareShare
About namespaces
 

XML namespaces are used to uniquely identify elements (XML element: An XML structure that consists of a start tag, an end tag, and the information between the tags. Elements can have attributes and can contain other elements.) and attributes (XML attribute: An XML structural construct. A name-value pair, separated by an equal sign and included in a tagged element, that modifies features of an element. All attribute values are text strings and must be enclosed in quotation marks.) within an XML document to avoid naming conflicts. Namespaces are declared as a Uniform Resource Identifier (URI) (Uniform Resource Identifier (URI): A character string used to identify a resource on the Internet by type and location.) and are typically located in the start tag of the root element (root element: The element in an XML document that contains all other elements. It is the top-level element of an XML document and must be the first element in the document.) of an XML document. However, they can also be defined at the node level, where they are valid for that node and all of its descendants. Associating a URI with a namespace ensures that elements with the same name remain distinct.

The Namespaces in XML recommendation, developed by the World Wide Web Consortium (W3C) (World Wide Web Consortium (W3C): A consortium of commercial and educational institutions that oversees research and promotes standards in all areas related to the World Wide Web.), provides the xmlns attribute to uniquely define a namespace for an XML document. The following is an example of a namespace that is used to define the vocabulary for Extensible Stylesheet Language Transformation (XSLT) (XSL Transformation (XSLT): A language that is used to transform XML documents into other types of documents, such as HTML or XML. It is designed for use as part of XSL.):

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

A namespace is divided into three sections:

After a namespace is declared for an XML document, any element or attribute that belongs to that namespace uses the namespace prefix in its declaration. For example, .xslt files use the xsl namespace prefix, as shown in the following example:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:output method="html" indent="no"/>
   <xsl:template match="myNode:myNodes">
      ...
   </xsl:template>
</xsl:stylesheet> 

© 2009 Microsoft Corporation. All rights reserved.