The primitive type xs:QName
represents an XML namespace-qualified name. In XQuery, xs:QName
values have three parts: the full namespace URI, the local part of the name, and the prefix. The namespace and the prefix are optional. If a QName does not have a namespace associated with it, it is considered to be in "no namespace."
When used in a query or schema, the lexical representation of an xs:QName
has just two parts: an optional prefix and the local part of the name. Based on the prefix, the context is used to determine the namespace URI. If the prefix is not present, either the name is in the default namespace or it is in no namespace at all.
Table B-19 lists some values of the xs:QName
type.
Table B-19. Values of the xs:QName type
The prefix itself has no meaning; it is just a placeholder. However, the XQuery processor does keep track of a QName's prefix. This simplifies certain processes such as serializing QNames and casting them to strings.
One of the most common ways of getting an xs:QName
is to use the node-name
function, which returns the name of an element or attribute as an xs:QName
value.
The xs:QName
type has a standard constructor that allows a value to be cast from xs:untypedAtomic
or from xs:string
. However, it has a special constraint that it can only accept a literal xs:string
value (not an evaluated expression) as its argument. The value may be prefixed, e.g., prod:number
, or unprefixed, e.g., number
. If a prefix is used, it must be declared.
Two additional functions can be used to construct xs:QName
values: QName
and resolve-QName
.
Two xs:QName
values can be compared using the =
and !=
operators. They are considered equal if they have the exact same namespace URI (based on Unicode code points) and the exact same local name (also based on Unicode code points); the prefixes are ignored. Because the xs:QName
type is not ordered, two xs:QName
values cannot be compared using the <
, <=
, >
, or >=
operators. The xs:QName
type is not derived from xs:string
, so you cannot compare them to strings directly.
More information on working with qualified names can be found in "Working with Qualified Names" in Chapter 20.
3.138.36.38