Modules

A guide to using modules in XmlPrime, and writing Modules as .NET types.

This topic contains the following sections.

Overview

A module is a collection of functions and global variables, all in the same target namespace that can be called from within an XQuery program, XPath expression or XSL transformation. A library is a set of modules all with the same target namespace. XmlPrime supports three types of modules: built-in modules, XQuery modules and native .NET modules. This document explains how modules are created and managed, and how to use them with XmlPrime.

The Library Set

All XQuery programs, XPath expressions and XSL transformations have an associated LibrarySetLibrarySetLibrarySet. The library set is exposed via the StaticContextSettings.LibrariesStaticContextSettings.LibrariesStaticContextSettings::Libraries property.

Modules can be added to the library set with the LibrarySet.Add (XdmModule)LibrarySet.Add (XdmModule)LibrarySet::Add (XdmModule^). This makes the module accessible to the XQuery program or XPath expression. The module can only be used however if its target namespace has been imported. A library can be imported either by adding an import module declaration to an XQuery program, or by calling the StaticContextSettings.ImportModule (string)StaticContextSettings.ImportModule (String)StaticContextSettings::ImportModule (String^) method. This function has the same effect as a module import at the start of an XQuery program, and the import is not processed until the query is compiled. An overload of StaticContextSettings.ImportModule (XdmModule)StaticContextSettings.ImportModule (XdmModule)StaticContextSettings::ImportModule (XdmModule^) exists which adds the module to the library set and imports its target namespace.

When a module import is processed any modules with the specified target namespace that exist in the library set are imported. If there are no modules with the specified target namespace in the module set then the location hints are resolved using the module resolver specified in XQuerySettings.ModuleResolverXQuerySettings.ModuleResolverXQuerySettings::ModuleResolver and the modules are compiled and added to the library set. If there are modules with the specified target URI in the library set then the location hints are not processed.

After compiling an XQuery program or XPath expression all modules imported will have been added to the module set, and the library set can be reused.

 
 
Tip
The library set can be used for the compilation of more than one XQuery program or XPath expression. Using the same module set for multiple queries means that any libraries imported will only be compiled once.