[Overview][Types][Classes][Procedures and functions][Index] Reference for unit 'Laz2_XPath' (#lazutils)

EvaluateXPathExpression

Evaluates an XPath expression using the specified context node and optional namespace resolver.

Declaration

Source position: laz2_xpath.pas line 466

function EvaluateXPathExpression(

  const AExpressionString: DOMString;

  AContextNode: TDOMNode;

  AResolver: TXPathNSResolver = Nil

):TXPathVariable;

Arguments

AExpressionString

  

XPath expression evaluated in the routine.

AContextNode

  

Context node for the XPath expression.

AResolver

  

Namespace resolver for the evaluation.

Function result

XPath variable representing the evaluated XPath expression.

Description

EvaluateXPathExpression is a TXPathVariable function used to locate and return a node or tree of nodes that match the XPath expression specified in AExpressionString. AExpressionString is similar to a SQL query, and is used to navigate and select DOM nodes found in the AContextNode argument.

Some examples (for specific xml document content) include:

/bookstore/book
/bookstore/book[1]
/bookstore/book[last()]
/bookstore/book[price<35.00]/title
//title[@lang]
//title[@lang="en"]
//title[starts-with(text(),"Introduction to")]
//book[@genre="Science Fiction"]
//*[contains(@class, "nav")]

XPath expressions and syntax are defined in the specification located at:

XML Path Language (XPath) Version 1.0, W3C Recommendation, 16 November 1999

AContextNode is a DOM node in an existing XML document, and provides the node tree searched in the routine. It may be be the root element in an XML document, but may also contain one the child nodes in a document to perform a limited search.

AResolver is a TXPathNSResolver instance which allows namespace prefixes and URLs to be validated while evaluating the XPath expression. It is an optional argument (the default value is Nil), and when omitted causes only the namespaces defined in AContextNode to be considered valid. The resolver instance must be created (when needed) using a DOM node which contains the namespace declarations for node prefixes that can be included in the XPath expression, and the nodes in the result set.

EvaluateXPathExpression creates a TXPathScanner instance used to parse and process the XPath expression, and to compare DOM nodes for inclusion in a result set. It is passed as an argument a TXPathExpression instance also created in the routine, and used to build the DOM tree that is the return value for the function. The evaluator is configured to perform a complete evaluation of the XPath expression, including phrases which are non-deterministic. It also returns the TXPathVariable instance with the DOM node(s) which match the evaluated expression.

The TXPathVariable return value may be cast to a type expected in the application using methods like AsNodeSet, AsBoolean, or AsText. It may also be cast to a specific class type like TXPathNodeSetVariable, TXPathBooleanVariable, TXPathNumberVariable, or TXPathStringVariable.

See also

TXPathExpression.Evaluate

  

Evaluates an XPath expression using the scanner for the class instance with the specified context node and XPath environment.

TXPathScanner

  

Implements a lexical scanner and parser using XPath syntax and semantics.

TXPathNSResolver

  

Implements a Namespace resolver for the XPath environment.

TXPathVariable

  

Base class used to represent an XPath variables and results.

TXPathNodeSetVariable

  

Represents an XPath Node Set variable.

TXPathBooleanVariable

  

Represents an XPath Boolean variable.

TXPathNumberVariable

  

Represents an XPath Number variable.

TXPathStringVariable

  

Represents an XPath String variable.

TDomNode

  

Implements the DOM Node interface.


Version 4.0 Generated 2025-05-03 Home