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.
- 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.
- 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.
- Create an instance
of the new extension function class.
- Create a TXmlEngExtensionFunctionDescriptor structure.
This structure contains a pointer to the new extension function, the
name of the function, and the optional namespace URI.
- Register this instance
by calling the static TXmlEngXPathConfiguration::AddExtensionFunctionL() function.
- Use the new extension
function in an XPath query.
- Free your resources
as necessary.