Namespaces and XQuery

Now that you have seen how namespaces are used in XML documents, let's look at how they are used in queries. Namespace-qualified names are used in queries in a number of ways:

  • The input documents may contain elements and attributes that are in one or more namespaces.

  • The query may construct new elements and attributes that are in one or more namespaces.

  • The functions that are declared and/or called in a query have qualified names. This includes user-defined functions and XQuery built-in functions.

  • The types used in a query have qualified names that are used, for example, in function signatures and in the constructors that create new values of that type.

    • Built-in types are in the XML Schema Namespace, and are conventionally prefixed with xs:.

    • User-defined types are in the target namespace of the schema document in which they are defined.

  • The variables used in a query have qualified names. Many variables will have no namespace and no prefix, but the names are still considered qualified names.

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.