QName
Encyclopedia
QNames were introduced by XML Namespace
XML Namespace
xmlns tagged XML namespaces are used for providing uniquely named elements and attributes in an XML document. They are defined in a W3C recommendation. An XML instance may contain element or attribute names from more than one XML vocabulary...

s in order to be used as URI
Uniform Resource Identifier
In computing, a uniform resource identifier is a string of characters used to identify a name or a resource on the Internet. Such identification enables interaction with representations of the resource over a network using specific protocols...

references. QName stands for "qualified name" and defines a valid identifier for elements and attributes. QNames are generally used to reference particular elements or attributes within XML documents.

Motivation

Since URI references can be long and may contain prohibited characters for element/attribute naming, QNames are used to create a mapping between the URI and a namespace prefix. The mapping enables the abbreviation of URIs, therefore it achieves a more convenient way to write XML documents. (see Example)

Formal definition

QNames are formally defined by the W3C as:

QName ::= PrefixedName | UnprefixedName

PrefixedName ::= Prefix ':' LocalPart
UnprefixedName ::= LocalPart


Whereby the Prefix is used as placeholder for the namespace and the LocalPart as the local part of the qualified name. A local part can be an attribute name or an element name.

Example








In line two the prefix "x" is declared to be associated with the URI "http://example.com/ns/foo". This prefix can further on be used as abbreviation for this namespace. Subsequently the tag "x:p" is a valid QName because it uses the "x" as namespace reference and "p" as local part. The tag "doc" is also a valid QName, but it consists only of a local part.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK