XML namespace: Difference between revisions

Content deleted Content added
Sentence fragment removed.
Rescuing 1 sources and tagging 0 as dead. #IABot (v1.1)
Line 5:
== Namespace names ==
 
A ''namespace name'' is a [[uniform resource identifier]] (URI). Typically, the URI chosen for the namespace of a given XML vocabulary describes a resource under the control of the author or organization defining the vocabulary, such as a [[uniform resource locator|URL]] for the author's Web server. However, the namespace specification does not require nor suggest that the namespace URI be used to retrieve information; it is simply treated by an XML parser as a string. For example, the document at http://web.archive.org/web/20060228232134/http://www.w3.org/1999/xhtml itself does not contain any code. It simply describes the [[XHTML]] namespace to human readers. Using a URI (such as <nowiki>"http://web.archive.org/web/20060228232134/http://www.w3.org/1999/xhtml"</nowiki>) to identify a namespace, rather than a simple string (such as "xhtml"), reduces the probability of different namespaces using duplicate identifiers.
 
Although the term ''namespace URI'' is widespread, the W3C Recommendation refers to it as the ''namespace name''. The specification is not entirely prescriptive about the precise rules for namespace names (it does not explicitly say that parsers must reject documents where the namespace name is not a valid [[Uniform Resource Identifier]]), and many XML parsers allow any character string to be used. In version 1.1 of the recommendation, the namespace name becomes an [[Internationalized Resource Identifier]], which licenses the use of non-ASCII characters that in practice were already accepted by nearly all XML software. The term ''namespace URI'' persists, however, not only in popular usage, but also in many other specifications from W3C and elsewhere.
Line 11:
Following publication of the Namespaces recommendation, there was an intensive debate about how a relative URI should be handled, with some intensely arguing that it should simply be treated as a character string, and others arguing with conviction that it should be turned into an absolute URI by resolving it against the base URI of the document.<ref>{{cite web|title=News from the trenches|first=Leigh|last=Dodds|date=24 May 2000|url=http://www.xml.com/pub/a/2000/05/24/deviant/index.html |publisher=O'Reilly Media, Inc.}}</ref> The result of the debate was a ruling from W3C that relative URIs were deprecated.<ref>{{citation|title=W3C XML Plenary decision on relative URI references in namespace declarations|first=Dan|last=Connolly|date=11 Sep 2000}}</ref>
 
The use of URIs taking the form of URLs in the http scheme (such as ''http://web.archive.org/web/20060228232134/http://www.w3.org/1999/xhtml'') is common, despite the absence of any formal relationship with the HTTP protocol. The Namespaces specification does not say what should happen if such a URL is dereferenced (that is, if software attempts to retrieve a document from this ___location). One convention adopted by some users is to place an [[RDDL]] document at the ___location.<ref>{{citation|first=Elliotte Rusty|last=Harold|title=RDDL Me This: What Does a Namespace URL Locate?|date=20 Feb 2001|url=http://www.oreillynet.com/pub/a/oreilly/xml/news/xmlnut2_0201.html}}</ref> In general, however, users should assume that the namespace URI is simply a name, not the address of a document on the Web.
 
== Namespace declaration ==
Line 18:
For example, the following declaration maps the "xhtml:" prefix to the XHTML namespace:
 
<pre><nowiki>xmlns:xhtml="http://web.archive.org/web/20060228232134/http://www.w3.org/1999/xhtml"</nowiki></pre>
 
Any element or attribute whose name starts with the prefix "xhtml:" is considered to be in the XHTML namespace, if it or an ancestor has the above namespace declaration.
Line 24:
It is also possible to declare a default namespace. For example:
 
<pre><nowiki>xmlns="http://web.archive.org/web/20060228232134/http://www.w3.org/1999/xhtml"</nowiki></pre>
 
In this case, any element without a namespace prefix is considered to be in the XHTML namespace, if it or an ancestor has the above default namespace declaration.