Default namespace declarations

Default namespace declarations are optional declarations in the XQuery expression prolog that specify the namespaces to use for unprefixed QNames (qualified names).

An XQuery expression prolog can include a default element namespace declaration.

The default element namespace declaration specifies a namespace URI that is used for unprefixed element names. The XQuery expression prolog can contain one default element namespace declaration only. This declaration is in scope throughout the expression in which it is declared. If no default element namespace is declared, unqualified element names are in no namespace.

Syntax

default-namespace-declaration
Read syntax diagramSkip visual syntax diagramdeclaredefaultelementnamespace stringLiteral;
namespace
Specifies a string literal that represents the URI for the namespace. The string literal must be a valid URI or a zero-length string.

If namespace is a zero-length string, unprefixed element names are in no namespace.

The string literal cannot be http://www.w3.org/XML/1998/namespace or http://www.w3.org/2000/xmlns/.

Example

The following declaration specifies that the default namespace for element names is the namespace that is associated with the URI http://posample.org
declare default element namespace "http://posample.org";

When the query in the example executes, all element nodes in this expression (purchaseOrder, shipTo, billTo, and name) are associated with the namespace URI http://posample.org.

declare default element namespace "http://posample.org";
/purchaseOrder[shipTo/name = "Jane" and billTo/name = "Jason"]

When the expression in the example executes, the namespace URI http://posample.org is associated with all unprefixed element names in the expression.