Namespace declarations
A namespace declaration is an optional declaration in the XQuery expression prolog that declares a namespace prefix and associates the prefix with a namespace URI.
xmlns
and xml
are reserved
and cannot be specified as a prefix in a namespace declaration.Syntax
- prefix
- Specifies a namespace prefix that is bound to the URI. The namespace prefix is used in qualified names (QNames) to identify the namespace for an element, attribute, data type, or function.
- stringLiteral
- Specifies a string literal that represents the URI to which the
prefix is bound. The string literal value must be a valid URI and
cannot be a zero-length string.
You can override predeclared namespace prefixes by specifying a namespace declarations for those prefixes. However, you cannot override the URI that is associated with the prefix
xml
.The string literal cannot be http://www.w3.org/XML/1998/namespace or http://www.w3.org/2000/xmlns/.
Example
The following namespace declaration
declares the namespace prefix ns1
and associates
it with the namespace URI http://posample.org
:
declare namespace ns1 = "http://posample.org";
/ns1:purchaseOrder[shipTo/name = "Jane" and billTo/name = "Jason"]
When
the expression in the example executes, the namespace prefix ns1 is
associated with the namespace URI http://posample.org. The instance
of the purchase order document to which the expression refers is the
instance with the namespace URI http://posample.org
.