转自:http://infohost.nmt.edu/tcc/help/pubs/pyxml/def-qname.html
2.7. qName
: Qualified name
A document may contain elements and attributes from more than one namespace URI. Because namespace URIs can be quite lengthy, it is cumbersome to include the complete namespace URI in each element or attribute name.
XML allows a shorthand notation to simplify assigning names to namespaces. You may invent a short namespace prefix and associate it with a namespace URI.
For example, suppose your document contains names from both the XSLT and XHTML namespaces. In this situation, it is customary to associate the namespace prefix “xsl
” with XSLT. You might use prefix “html
” to refer to the XHTML namespace.
A qualified name has three parts:
A namespace prefix.
A colon character, “
:
”.A local name that gives the name of the element or attribute within that namespace.
For example, here is a fragment illustrating the use of qualified names:
<xsl:template match="separator">
<html:hr/>
</xsl:template>
Element template
is in the XSLT namespace, and element hr
is in the HTML namespace.
You can also use an unqualified name, which is just a local name without the namespace prefix. The namespace of such a name is called the default namespace.
The association between a namespace prefix and a namespace URI is made with an xmlns
attribute located in some element. This attribute can have two forms:
An attribute named
xmlns='
defines the namespace URI of the default namespace. This namespace is associated with all elements and attributes that have unqualified names.nsURI
'An attribute named
xmlns:
associates the givenprefix
='nsURI
'
with the namespace URIprefix
.nsURI
Here is an example of a complete document using elements from two namespaces:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
version="1.0">
<xsl:template match="foo">
<hr/>
</xsl:template>
</xsl:stylesheet>
In this example, the template
element is in the XSLT namespace. The hr
element is in the default namespace, which is associated with the XHTML namespace URI.