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.

Before you start, you must:

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.

  1. Write a new class that implements the 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 MXPathExtensionFunction interface. This class represents the new extension function. The MXPathExtensionFunction::Evaluate() function uses its 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 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 TXmlEngXPathConfiguration::AddExtensionFunctionL() function.
  6. Use the new extension function in an XPath query.
  7. Free your resources as necessary.