Using XPath Extension Function

This topic explains how to use the XPath Extension Function API to implement XPath functions and register them with the XML DOM Engine.

Context

XPath is a query language for exploring XML documents. You can extend it with domain-specific functions or with general utility functions, to add functionality to XPath queries.

Prerequisites

Before you start, you must:

Steps

  1. Write a new class that implements the [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]MXmlEngXPathEvaluationContext interface.

    This class represents the evaluation context. It processes the arguments of the extension function and stores the result of the evaluation.

  2. Write a new class that implements the [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]MXPathExtensionFunction interface.

    This class represents the new extension function. The [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]MXPathExtensionFunction::Evaluate() function uses its [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]MXmlEngXPathEvaluationContext parameter to process input arguments and return a result. This result can be a set of nodes, a number, a boolean or a string.

  3. Create an instance of the new extension function class.

  4. Create a [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]TXmlEngExtensionFunctionDescriptor structure.

    This structure contains a pointer to the new extension function, the name of the function, and the optional namespace URI.

  5. Register this instance by calling the static [[[ERROR: [NOKX000E] Unable to find definition for key reference 'XML']]]TXmlEngXPathConfiguration::AddExtensionFunctionL() function.

  6. Use the new extension function in an XPath query.

  7. Free your resources as necessary.

Related tasks