Namespace declaration
The namespace declaration is in scope throughout the query in which it is declared, unless the declaration is overridden by a namespace declaration attribute in a direct element constructor. Multiple declarations of the same namespace prefix in the query prolog result in an error.
Syntax
- prefix
- Specifies a namespace prefix that is bound to the URI that is
specified by URILiteral. The namespace prefix is
used in qualified names (QNames) to identify the namespace for an
element, attribute, data type, or function.
The prefixes
xmlns
andxml
are reserved and cannot be specified as prefixes in namespace declarations. - URILiteral
- Specifies the URI to which the prefix is bound. URILiteral must be a non-zero-length literal string that contains a valid URI.
Example
The following query includes a namespace
declaration that declares the namespace prefix ns1
and
associates it with the namespace URI http://posample.org
:
declare namespace ns1 = "http://posample.org";
<ns1:name>Thermal gloves</ns1:name>
When
the query in the example executes, the newly created node (an element
node called name
) is in the namespace that is associated
with the namespace URI http://posample.org
.
Predeclared namespace prefixes
XQuery has several predeclared namespace prefixes that are present in the statically known namespaces before each query is processed. You can use any of the predeclared prefixes without an explicit declaration. The predeclared namespace prefixes for Db2 XQuery include the prefix and URI pairs that are shown in the following table:
Prefix | URI | Description |
---|---|---|
xml | http://www.w3.org/XML/1998/namespace |
XML reserved namespace |
xs | http://www.w3.org/2001/XMLSchema |
XML Schema namespace |
xsi | http://www.w3.org/2001/XMLSchema-instance |
XML Schema instance namespace |
fn | http://www.w3.org/2005/xpath-functions |
Default function namespace |
xdt | http://www.w3.org/2005/xpath-datatypes |
XQuery type namespace |
db2-fn | http://www.ibm.com/xmlns/prod/db2/functions |
Db2 function namespace |
You can override predeclared namespace prefixes by specifying
a namespace declaration in a query prolog. However, you cannot override
the URI that is associated with the prefix xml
.