An implementation of the XML Path Language (XPath) for Free Pascal.

laz2_xpath.pas provides an implementation of the XML Path Language (XPath) for the Lazarus IDE. It is based on the xpath.pp unit from the Free Component Library (FCL).

Copyright (c) 2000 - 2003 by Areca Systems GmbH / Sebastian Guenther, sg@freepascal.org

This implementation is based on the following specification:

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

This file is part of the LazUtils package.

Identifies token types used in XPath expressions. Token is not a valid XPath expression. End of the XPath data stream. Token is a function name. Token contains a namespace prefix Token is a string literal. Token contains a numeric digit. Token is a variable reference. Token contains the ( operator. Token contains the ) operator. Token contains the * operator. Token contains the + operator. Token contains the , (Comma) expression separator. Token contains the - operator. Token contains a the current node (.) expression Token contains the parent node (..) expression. Token contains the / operator. Token contains the // operator. Token contains the :: axis operator. Token contains the LessThan operator. Token contains the LessThanOrEqual operator. Token contains the = operator. Token contains the != operator. Token contains the GreaterThan operator. Token contains the GreaterThanOrEqual operator. Token contains the @ expression character. Token contains the [ expression separator. Token contains the ] expression separator. Token contains the operator | expression character. Represents keywords used in XPath syntax. TXPathKeyword is an enumeration type that represents the axis names, node tests, operators, and standard functions available in XPath syntax. No axis specified. Ancestor axis (ancestor::). Ancestor or Self axis (ancestor-or-self::). Attribute axis (attribute::). Child axis (child::). Descendant axis (descendant::). Descendant or Self axis (descendant-or-self::). Following axis (following::). Following Sibling axis (following-sibling::). Namespace axis (namespace::). Parent axis (parent::). Preceding axis (preceding::). Preceding Sibling axis (preceding-sibling::). Self axis (self::). Node test for comment: comment(). Node test for text: text(). Node test for preceding instruction: processing-instruction(). Node test for a node: node(). And operator. Or operator. Div operator. Mod operator. Node set function last(). Node set function position(). Node set function Count(node-set). Unique ID function: id("foo"). Node set function local-name(node-set). Node set function namespace-uri(node-set). Node set function name(node-set). String function string(object). String function concat(string, string). String function starts-with(string, string). String function contains(string, string). String function substring-before(string, string). String function substring-after(string, string). String function substring(string, number, number). String function string-length(string). String function normalize-space(string). String function translate(string, string, string). Boolean function boolean(object). Boolean function not(boolean). Boolean function true(). Boolean function false(). Boolean function lang(string). Number function number(object). Number function sum(node-set). Number function floor(number). Number function ceiling(number). Number function round(number). Defines the base class used to evaluate XPath expressions.

TXPathExprNode is a class used to evaluate an XPath expression. XPath expressions are evaluated relative to a context node, and the XPath environment. The XPath environment may contain variable bindings, the XPath core functions, and other functions loaded from other namespaces.

TXPathExprNode provides the abstract Evaluate method which is used to perform XPath expression evaluation. It must be re-implemented in descendent classes which provide support for specific expression types that can occur in XPath syntax.

Evaluates an XPath Predicate Expression.

EvalPredicate is a Boolean function used to evaluate an XPath Predicate Expression. EvalPredicate calls the Evaluate method using the specified Content node and Environment. An Expression that evaluates to a numeric value is considered to be True when the result matches the ContextPosition in the AContext argument.

EvalPredicate is used in the implementation of other specialized Predicate Expressions types descended from TXPathExprNode.

Boolean result for the evaluated expression. Context node for the expression. XPath environment for the evaluation. Specifies the method used to evaluate an XPath Predicate Expression.

Evaluate is an abstract virtual TXPathVariable function which specifies the interface used to evaluate an XPath Predicate Expression. Evaluate must be implemented in descendent classes which handles specific Predicate Expression types in the XPath syntax.

Contains the result for the evaluated expression. Context node for the expression. XPath environment for the evaluation. Array used to store TXPathExprNode entries.

TXPathNodeArray is an array of TXPathExprNode type. It is used to store XPath predicate expressions passed as arguments to TXPathExprNode descendants or TXPathScanner.

Represents an XPath literal expression.

TXPathConstantNode is a TXPathExprNode descendant that represents an XPath predicate expression which contains a literal value (any value surrounded by Quotation Marks). The return value is the TXPathVariable passed to the constructor for the class instance.

Constructor for the class instance. XPath variable with the value for the literal expression. Destructor for the class instance. Returns the value for the constant node and increments its reference count.

The context node and the XPath environment arguments are not used in the method.

Value for the constant node. Context node for the evaluation. XPath environment for the evaluation. Represents an XPath variable expression.

TXPathVariableNode is a TXPathExprNode descendant that represents an XPath Variable Reference expression in the XPath syntax. For example:

$prefix:varname

TXPathVariableNode provides an overridden Evaluate method that is used to get the value for the node from the variable bindings in the XPath environment.

Constructor for the class instance. Name for the variable. Evaluates the XPath expression.

Evaluate is an overridden method used to evaluate the XPath expression and return its derived value. Evaluate implements the abstract method defined in the ancestor class.

For TXPathVariableNode, Evaluate uses the XPath environment passed in the AEnvironment argument to retrieve the value for the variable. If a variable is not found with the required name in the XPath environment, the EvaluationError method is called to raise an exception with the message in lrsEvalUnknownVariable.

Raises an exception (in EvaluationError) when the variable name does not exist in the XPath environment. Raised with the exception message in lrsEvalUnknownVariable.

Result for the evaluated expression. Context node for the function. XPath environment for the evaluation. Represents an XPath Function expression.

TXPathFunctionNode is a TXPathExprNode descendant that represents a Function Name expression in the XPath syntax. For example:

local-name() or ms:utc()

TXPathFunctionNode provides an overridden Evaluate method which is used to access the named function in the XPath environment with the arguments found in the expression. TXPathFunctionNode provides private members that are used to store the name for the function and its optional arguments.

Constructor for the class instance. Name of the XPath function represented by the class instance. TXPathNodeArray instance with the arguments passed to the function. Destructor for the class instance. Evaluates the XPath function name using the specified context and environment.

Evaluate is an overridden TXPathVariable function that implements the method defined in the ancestor class. Evaluate is used to derive the value for the function call using any arguments found in the XPath expression, and to store the result in the TXPathVariable return value.

Evaluate uses the AEnvironment parameter to access the function names (and their implementations) available in the XPath environment. If a function with the required name is not found in AEnvironment, the EvaluationError routine is called to raise an exception with the message in lrsEvalUnknownFunction.

Evaluate creates an internal TXPathVarList instance that is used to store the value for any arguments in the XPath expression. The list, and the context node in AContext, are passed to the function call. The internal list is freed prior to exiting from the method.

Result for the evaluated function. Context node for the evaluation. XPath environment for the evaluation. Represents an XPath Negation expression.

TXPathNegationNode is a TXPathExprNode descendant used to represent a Unary Expression with a Negation literal in the XPath syntax. For example:

-$varname

TXPathNegationNode provides an overridden Evaluate method used to derive the return value for the expression.

Constructor for the class instance. Operand in the XPath expression. Destructor for the class instance. Evaluates the XPath expression.

Evaluate is an overridden TXPathVariable function used to get the derived value for the XPath expression. Evaluate implements the abstract method defined in the ancestor class.

Evaluate uses the value in the AContext and AEnvironment parameters to calculate the numeric value for the expression.

Result for the evaluated expression. Context node for the expression. XPath environment for the evaluation. The base class for XPath expressions which represent Binary operations. Destructor for the class instance. Identifies the binary Math Operators used in XPath expressions.

Used in the implementation of the TXPathMathOpNode class.

The Addition (+) operator. The Subtraction (-) operator. The Multiplication (*) operator. The Division (/) operator. The Modulus (mod) operator. Represents a Math Operation in an XPath expression.

TXPathMathOpNode is a TXPathBinaryNode descendant used to represent a math operation in an XPath expression. TXPathMathOpNode is used for the Additive and Multiplicative Expressions defined in the XPath specification. The constructor accepts the operator and the operands from the expression. TXPathMathOpNode provides an overridden Evaluate method used to derive the value for the XPath expression.

Constructor for the class instance. Math operator used in the XPath expression. Left hand Operand. Right hand Operand. Evaluates the XPath expression. Result for the evaluated expression. Context node for the expression. XPath environment for the evaluation. Identifies Comparison operators used in an XPath expression.

Used in the implementation of the TXPathCompareNode class.

The Equality (=) operator. The Inequality (!=) operator. The Less Than (<) operator. The Less Than Or Equal (<=) operator. The Greater Than (>) operator. The Greater Than Or Equal (>=) operator. Represents an XPath Comparison expression.

TXPathCompareNode is a TXPathBinaryNode descendant used to represent Equality or Relational expressions in the XPath syntax.

TXPathCompareNode contains an overridden constructor used to specify the operator and operands for the comparison expression. TXPathCompareNode provides an overridden Evaluate method which compares the nodes or node sets for the XPath expression.

Constructor for the class instance. Operator for the comparison. Left hand Operand. Right hand Operand. Evaluate the XPath Comparison expression. Result for the comparison. Context node for the expression. XPath environment for the evaluation. Represents Boolean operators in an XPath expression. The OR operator. The AND operator. Represents a Boolean expression in XPath syntax.

TXPathBooleanOpNode is a TXPathBinaryNode descendant used to represent an And or Or expression in XPath syntax. TXPathBooleanOpNode provides an overridden constructor that specifies the operator and operands for the XPath expression. TXPathBooleanOpNode contains an overridden Evaluate method which performs the comparison using Boolean short-circuit logic; i. e. the second operand is ignored if the result can be determined using the first operand.

Constructor for the class instance. Operator for the Boolean expression. Left hand operand. Right hand operand. Evaluates the XPath expression. Result for the evaluated expression. Context node for the expression. XPath environment for the evaluation. Represents a Union Expression node.

TXPathUnionNode is a TXPathBinaryNode descendant used to represent a Union expression in the XPath syntax. For example:

./child::*|./attribute::*

TXPathUnionNode provides a constructor used to set the operands for the Union expression. An overridden Evaluate method is provided to evaluate node sets generated for the XPath expression. It ensures that the selected node sets for each operand are in document order.

Constructor for the class instance. Left hand operand. Right hand operand. Evaluates the XPath expression. Result for the evaluated expression. Context node for the expression. XPath environment for the evaluation. Implements an XPath Node Set.

TNodeSet is a class alias used to implement a Node Set as defined in the XPath specification. TNodeSet is an alias for the TFPList class.

Implements an XPath Filter expression.

TXPathFilterNode is a TXPathExprNode descendant used to implement a Filter expression in the XPath syntax. For example:

//book[@*]

TXPathFilterNode allows a node set to be filtered to ensure that only values matching the XPath expression are included in the result. An overridden Evaluate method is provided to generate the node set in the return value, and to apply predicates in the XPath expression.

Applies Predicates to the XPath Node Set. Node Set used as the context nodes for predicate expressions. XPath environment for the evaluation. Constructor for the class instance. XPath Expression to use in the class instance. Destructor for the class instance. Evaluates the XPath expression. Result for the evaluated expression. Context node for the expression. XPath environment for the evaluation. Identifies an XPath Axis used in an XPath expression. An invalid Axis name in the XPath syntax. The ancestor:: Axis. The ancestor-or-self:: Axis. The attribute:: Axis. The child:: Axis. The descendant:: Axis. The descendant-or-self:: Axis. The following:: Axis. The following-sibling:: Axis. The namespace:: Axis. The parent:: Axis. The preceding:: Axis. The preceding-sibling:: Axis. The self:: Axis. The root:: Axis. Represents XPath Node Test types. The Any Principal Node Test type. The Name Node Test type. The Text Node Test type. The Comment Node Test type. The Processing Instruction Node Test type. The Any Node Test type. Implements an XPath Location Step.

TStep is a TXPathFilterNode descendant used to implement a Location Step expression in the XPath syntax. A location step expression contains an Axis name, a node test, and optional predicates that determine the items available in a node set. For example:

./child::book[@lang='en']

Use the constructor to specify the Axis and Node Test for the XPath expression. An overridden Evaluate method is provided to select the nodes included in the node set returned by the method.

Builds the Node Set for the XPath Location Step. Context node for the Location Step. Node Set for the evaluated expression. Axis type for the Location Step. Node Test Type for the Location Step. Node Test Type as a String value. Namespace Test as a String value. Constructor for the class instance. Axis type to use for the Location Step. Node Test Type to use for the Location Step. Evaluates the XPath expression for the Location Step. Result for the evaluated expression. Context node for the expression. XPath environment for the evaluation. Exception raised when an error occurs during XPath expression evaluation. Raises an exception during expression evaluation with the specified error message. Message for the evaluation error. Arguments used to format the message for the evaluation error. Base class used to represent an XPath variables and results.

TXPathVariable is a class used to represent Variables and Results for an XPath expression. TXPathVariable is a base class, and contains abstract methods which must be implemented in descendent classes for the Node Set, String, Number, and Boolean data types allowed in XPath variables and results.

TXPathVariable is used as the return type for the Evaluate method in TXPathExprNode and descendent classes. It is also used as the return value for Functions implemented in TXPathEnvironment.

Raises an exception with the specified message and arguments. Message for the error. Arguments used to format the message for the error. Gets the Type name for the XPath variable class instance. Value for TypeName. Decrements the reference count for the variable. Gets the XPath variable as a node set. Value for the variable as a Node Set. Gets the XPath variable as a Boolean value. Value for the variable as a Boolean data type. Gets the XPath variable as a Numeric value. Value for the variable as a Numeric data type. Gets the XPath variable as a String value. Value for the variable as a String data type. Represents an XPath Node Set variable.

TXPathNodeSetVariable is a TXPathVariable used to represent a Node Set variable. TXPathNodeSetVariable implements the abstract methods defined in the ancestor class, and contains an internal TNodeSet member used to store the nodes in the node set.

Use the Value property to access the XPath variable as a TNodeSet class instance. Use AsText, AsNumber, or AsBoolean to access the value for the variable using the corresponding data type.

Constructor for the class instance. Value for the Node Set variable. Destructor for the class instance. Gets the Type Name for the variable class. Value for the Node Type name. Gets the Node Set in its native format. Value for the Node Set variable as a Node Set type. Gets the Node Set as a String value. Value for the Node Set variable as a String data type. Gets the Node Set as a Boolean value. The return value is True when the Count property for the mode set is not 0. Value for the Node Set variable as a Boolean data type. Gets the Node Set as a Numeric value. Value for the Node Set variable as a Numeric data type. Value for the Node Set variable. Represents an XPath Boolean variable. Constructor for the class instance. Initial value for the variable. Gets the value for TypeName. The value for TypeName. Gets the value for the Boolean variable as a Boolean data type. Boolean value for the variable. Gets the value for the Boolean variable as a Numeric data type. Numeric value for the variable. Gets the value for the Boolean variable as a String data type. String value for the variable. Value for the Boolean variable. Represents an XPath Number variable. Constructor for the class instance. Initial value for the variable. Type Name for the variable. Value for TypeName. Gets the value for the Numeric variable as a Boolean data type. Boolean value for the variable. Gets the value for the Numeric variable as a Numeric data type. Numeric value for the variable. Gets the value for the Numeric variable as a String data type. String value for the variable. Value for the Numeric variable. Represents an XPath String variable. Constructor for the class instance. Initial value for the variable. Gets the Type Name for the variable. Value for TypeName. Gets the value for the variable as a Boolean data type. Boolean value for the variable. Gets the value for the variable as a Numeric data type. Numeric value for the variable. Gets the value for the variable as a String data type. String value for the variable. Value for the variable. Implements a Namespace resolver for the XPath environment.

TXPathNSResolver is a class used to implement a Namespace resolver for the XPath environment. TXPathNSResolver performs namespace look-ups for Qualified Names which include a prefix. Namespaces are resolved relative to the context node passed to the constructor for the class instance.

TXPathNSResolver is used in the implementation of TXPathScanner, TXPathExpression, and passed as an argument to the EvaluateXPathExpression routine.

Constructor for the class instance. Context node for the Namespace Resolver. Gets the Namespace URI with the specified Prefix. Namespace prefixes and URI are resolved relative to the context node for the resolver. Namespace URI for the specified Prefix. Prefix to locate in the Namespace information for the Context node. Implements a lexical scanner and parser using XPath syntax and semantics.

TXPathScanner is a class which implements a lexical scanner/parser using the syntax and semantics defined in XPath (XML Path Language). TXPathScanner provides methods used to tokenize and parse the XPath Expression types defined in the specification, at:

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

TXPathScanner examines an XPath expression, and creates a parse tree representing the lexical and syntactic elements found in the expression. The parse tree consists of TXPathExprNode (and descendent) class instances which evaluate the XPath expressions and generate the result(s).

TXPathScanner is used in the implementation of the TXPathExpression class.

Raises an exception with the specified message. Message for the error. Parses XPath Predicate expressions. Destination nodes for XPath predicates in the expression. Parses XPath Location Steps in the expression. TStep class instance for the Location Step. Parses XPath Node Tests to determine the principal node type for the expression. TStep class instance for the Location Step. Axis to use for the Location Step in the result value. Parses a Primary Expression in the XPath expression. Primary expression parsed in the method. Parses a FunctionCall Expression in the XPath expression. Function call parsed in the method. Parses a Union Expression in the XPath expression. Union expression parsed in the method. Parses a Path Expression in the XPath expression. Path expression parsed in the method. Parses a Filter Expression in the XPath expression. Filter expression parsed in the method. Parses an Or expression in the XPath expression. Or expression parsed in the method. Parses an And Expression in the XPath expression. And expression parsed in the method. Parses an Equality Expression in the XPath expression. Equality expression parsed in the method. Parses a Relational Expression in the XPath expression. Relational expression parsed in the method. Parses an Additive Expression in the XPath expression. Additive expression parsed in the method. Parses a Multiplicative Expression in the XPath expression. Multiplicative expression parsed in the method. Parses an Unary Expression in the XPath expression. Unary expression parsed in the method. Gets a lexical token in the XPath expression. Lexical token read in the scanner. Locates a Qualified Name in a token. False if the token does not contain a valid QName. Constructor for the class instance. XPath expression examined in the scanner/parser. Gets the next token in the XPath expression. Token kind located in the method. Peeks at the token kind for the next lexical element. Value for the pending logical token in the scanner. Skips the current token when it is not an error. True if the current token is the same as the tok argument. Token expected in the method. Current token kind in the lexical analysis. Current token value in the lexical analysis. Represents the Context for an XPath expression. The node for the XPath context. The position in the context node. The size (or length) of the context node set. Constructor for the class instance. Context node for the expression. Position in the context node. Size (or length) of the context node set. List used to store XPath variables in the XPath environment. Implements an XPath function. XPath variable returned from the XPath function implementation. Context node for the expression. Arguments for the function. Provides access to functions and variables available in the XPath environment.

TXPathEnvironment is a class which provides access to the core function library and variable bindings available for use in an XPath context. TXPathEnvironment is not an interface that is directly mandated in the XPath specification, but the functionality it provides is required for any XPath Context node.

TXPathEnvironment provides methods used to add or remove Functions or Variables in the XPath environment. Properties are provided to access Functions and Variables by their name or their ordinal position. The Functions property is pre-populated with the Core Function Library described in the XPath specification.

Gets the value for the FunctionCount property. TXPathEnvironment.FunctionCount Value for the FunctionCount property. Gets the value for the VariableCount property. TXPathEnvironment.VariableCount Value for the VariableCount property. Gets the Function with the specified Name or ordinal position. XPath function with the specified name or ordinal position. Ordinal position for the requested function. Name for the requested function. Gets the variable with the specified name or ordinal position. XPath variable with the specified name or ordinal position. Ordinal position for the requested variable. Name for the requested variable. Implements the last() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the position() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the count() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the id() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the local-name() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the namespace-uri() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the name() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the string() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the concat() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the starts-with() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the contains() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the substring-before() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the substring-after() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the substring() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the string-length() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the normalize-space() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the translate() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the boolean() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the not() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the true() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the false() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the lang() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the number() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the sum() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the floor() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the ceiling() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Implements the round() function from the XPath Core Function Library. Variable returned by the XPath function. Context node for the function. Arguments for the function. Constructor for the class instance. Destructor for the class instance. Gets the ordinal position of the XPath function with the specified name. Ordinal position of the XPath function with the specified name. Name of the XPath function to locate in the Functions property. Gets the ordinal position of the variable with the specified name. Ordinal position of the variable with the specified name. Name of the variable to locate in the Variables property. Adds a function to the Functions property with the specified name. Name for the function added to the Functions property. Function implementation to use for the specified function name. Adds a variable with the given name and value to the Variables property. Name of the variable added in the method. Value for the variable added in the method. Removes a function with the specified name or ordinal position from the Functions property. Ordinal position for the Function with the specified name. Name of the function to remove from the Functions property. Removes a variable with the specified name or ordinal position. Ordinal position for the variable to remove from the XPath environment. Name of the variable to remove from the XPath environment. Indicates the number of XPath functions in the XPath environment. Indicates the number of variables defined in the XPath environment. Provides indexed access to XPath functions in the environment. Ordinal position for the requested XPath function. Gets an XPath function with the specified name. Name for the requested XPath function. Provides indexed access to XPath variables in the XPath environment. Ordinal position for the requested variable. Gets an XPath variable with the specified name. Name of the requested variable. Evaluates an XPath expression using the specified scanner and resolver. Constructor for the class instance.

Create is the constructor for the class instance, and calls the inherited method on entry. Create uses AResolver as the value for the Resolver property in AScanner. It also updates the internal root node for the expression retrieved by calling the ParseOrExpr method in AScanner.

Create raises an EXPathEvaluationError exception if the scanner contains unused token after evaluating the XPath expression and the CompleteExpression argument is set to True.

Lexical scanner/parser used to evaluate the expression. The XPath expression evaluated in the class instance. Namespace resolver used to evaluate the expression. Destructor for the class instance. Evaluates an XPath expression using the scanner for the class instance with the specified context node and environment. Value from the evaluated expression. Context node for the expression. XPath environment for the evaluation. Evaluates an XPath expression using the specified context node and optional namespace resolver.

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. XPath syntax is 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.

XPath variable representing the evaluated XPath expression. XPath expression evaluated in the routine. Context node for the XPath expression. Namespace resolver for the evaluation.