Namespace Declarations in Queries

There are three ways that namespaces are mapped to prefixes in XQuery queries:

  • Some namespaces are predeclared; no explicit namespace declaration is necessary to associate a prefix with the namespace.

  • Namespace declarations can appear in the query prolog.

  • Namespace declarations can appear in direct XML constructors.

The examples in this section use the input document cat_ns.xml shown in Example 10-4.

Predeclared Namespaces

For convenience, five commonly used namespace declarations are built into the XQuery recommendation. They are listed in Table 10-1. The five prefixes can be used anywhere in a query even if they are not explicitly declared by a namespace declaration. These prefixes are also used throughout this book to represent the appropriate namespaces.

Table 10-1. Predeclared namespaces

Prefix

Namespace

Uses

xml

http://www.w3.org/XML/1998/namespace

XML attributes such as xml:lang and xml:space

xs

http://www.w3.org/2001/XMLSchema

XML Schema built-in types and their constructors

xsi

http://www.w3.org/2001/XMLSchema-instance

XML Schema instance attributes such as xsi:type and xsi:nil

fn

http://www.w3.org/2005/xpath-functions

XPath Functions Namespace: the default namespace of all built-in functions

local

http://www.w3.org/2005/xquery-local-functions

Functions declared in a main module that are not in a specific namespace

In addition, your XQuery implementation may predeclare other namespaces for use within your ...

Get XQuery now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.