Class TXQueryEngine

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TXQueryEngine = class(TObject)

Description

This is the XPath/XQuery-engine

You can use this class to evaluate a XPath/XQuery-expression on a certain document tree.
For example, TXQueryEngine.evaluateStaticXPath2('expression', nil) returns the value of the evaluation of expression.

Syntax of a XQuery / XPath / Pseudo-XPath-Expression

This query engine currently supports XPath 2.0, XQuery 1.0 and JSONiq, with some extensions and minor deviations, as well as parts of XPath 3.0 and XQuery 3.0.

A formal syntax definition of these languages is given at: http://www.w3.org/TR/xpath20/ , http://www.w3.org/TR/xquery/ , http://www.jsoniq.org/ , http://www.w3.org/TR/xpath-30/ and http://www.w3.org/TR/xquery-30/ .

Some very basic, standard XPath examples, for people who have never seen XPath before:

Differences between this implementation and standard XPath/XQuery (most differences can be turned off with the respective option or the field in the default StaticContext):

Extended syntax:

New functions:

You can look at the unit tests in the tests directory to see many (> 5000) examples.

Using the class in FPC

You can evaluate XQuery/XPath-expressions by just calling the class methods, e.g. TXQueryEngine.evaluateStaticXPath3('expression', nil) or TXQueryEngine.evaluateStaticXPath2('expression', nil).toInt64 which returns the value of the expression, converted to the corresponding type.
If you want to process a html/xml document, you have to pass the root TTreeNode (obtained by TTreeParser) instead of nil.


If you call TXQueryEngine.evaluateStaticXPath3('expression', nil) without a following toType-call, you obtain the result as an IXQValue. (see IXQValue on how to use it)
With a toType-call it is converted in the corresponding type, e.g. toInt64 returns a int64, toString a string, toNode a TTreeNode or toDecimal an extended.

You can also create a TXQueryEngine instance and then call parseXPath2('expression') and evaluateXPath2().
This is not as easy, but you have more options.

The unit simpleinternet provides a simpler procedural interface with its function simpleinternet.process .



Compatibility to previous version
The following major breaking changes occured to make it more standard compatible:

Hierarchy

Overview

Fields

Public CurrentDateTime: TDateTime;
Public ImplicitTimezone: TDateTime;
Public StaticContext: TXQStaticContext;
Public VariableChangelog: TXQVariableChangeLog;
Public OnDeclareExternalVariable: TXQDeclareExternalVariableEvent;
Public OnDeclareExternalFunction: TXQDeclareExternalFunctionEvent;
Public OnImportModule: TXQImportModuleEvent;
Public OnTrace: TXQTraceEvent;
Public OnCollection: TXQEvaluateVariableEvent;
Public OnParseDoc: TXQParseDocEvent;
Public ParsingOptions: TXQParsingOptions;
Public GlobalNamespaces: TNamespaceList;
Public AutomaticallyRegisterParsedModules: boolean;

Methods

Public procedure clear;
Public function parseXPath2(s:string; sharedContext: TXQStaticContext = nil): IXQuery;
Public function parseXQuery1(s:string; sharedContext: TXQStaticContext = nil): IXQuery;
Public function parseXPath3(s:string; sharedContext: TXQStaticContext = nil): IXQuery;
Public function parseXQuery3(s:string; sharedContext: TXQStaticContext = nil): IXQuery;
Public function parseCSS3(s:string): IXQuery;
Public function parseQuery(s:string; model: TXQParsingModel; sharedContext: TXQStaticContext = nil): IXQuery;
Public function evaluate(const context: TXQEvaluationContext): IXQValue;
Public function evaluate(const contextItem: IXQValue): IXQValue;
Public function evaluate(tree:TTreeNode = nil): IXQValue;
Public constructor create;
Public destructor Destroy; override;
Public function evaluateXPath2(expression: string; tree:TTreeNode = nil): IXQValue;
Public function evaluateXPath2(expression: string; const contextItem: IXQValue): IXQValue;
Public function evaluateXQuery1(expression: string; tree:TTreeNode = nil): IXQValue;
Public function evaluateXQuery1(expression: string; const contextItem: IXQValue): IXQValue;
Public function evaluateXPath3(expression: string; tree:TTreeNode = nil): IXQValue;
Public function evaluateXPath3(expression: string; const contextItem: IXQValue): IXQValue;
Public function evaluateXQuery3(expression: string; tree:TTreeNode = nil): IXQValue;
Public function evaluateXQuery3(expression: string; const contextItem: IXQValue): IXQValue;
Public function evaluateCSS3(expression: string; tree:TTreeNode = nil): IXQValue;
Public function evaluateCSS3(expression: string; const contextItem: IXQValue): IXQValue;
Public class function evaluateStaticXPath2(expression: string; tree:TTreeNode = nil): IXQValue;
Public class function evaluateStaticXPath2(expression: string; const contextItem: IXQValue): IXQValue;
Public class function evaluateStaticXPath3(expression: string; tree:TTreeNode = nil): IXQValue;
Public class function evaluateStaticXPath3(expression: string; const contextItem: IXQValue): IXQValue;
Public class function evaluateStaticXQuery1(expression: string; tree:TTreeNode = nil): IXQValue;
Public class function evaluateStaticXQuery1(expression: string; const contextItem: IXQValue): IXQValue;
Public class function evaluateStaticXQuery3(expression: string; tree:TTreeNode = nil): IXQValue;
Public class function evaluateStaticXQuery3(expression: string; const contextItem: IXQValue): IXQValue;
Public class function evaluateStaticCSS3(expression: string; tree:TTreeNode = nil): IXQValue;
Public procedure registerModule(module: IXQuery);
Public function findModule(const namespaceURL: string): TXQuery;
Public class function findNativeModule(const ns: string): TXQNativeModule;
Public class procedure registerCollation(const collation: TXQCollation);
Public class function getCollation(id:string; base: string): TXQCollation;
Public class procedure registerNativeModule(const module: TXQNativeModule);
Public class function collationsInternal: TStringList;
Public function getEvaluationContext(staticContextOverride: TXQStaticContext = nil): TXQEvaluationContext;

Properties

Public property ExternalDocumentsCacheInternal: TStringList read FExternalDocuments write FExternalDocuments;
Public property LastQuery: IXQuery read FLastQuery;

Description

Fields

Public CurrentDateTime: TDateTime;

Current time

Public ImplicitTimezone: TDateTime;

Local timezone (nan = unknown, 0 = utc).

Public StaticContext: TXQStaticContext;

XQuery static context, defining various default values.

Public VariableChangelog: TXQVariableChangeLog;

All global variables that have been set (if a variable was overriden, it stores the old and new value)

Public OnDeclareExternalVariable: TXQDeclareExternalVariableEvent;

Event called to import a variable that is declared as "declare variable ... external" in a XQuery expression

Public OnDeclareExternalFunction: TXQDeclareExternalFunctionEvent;

Event called to import a function that is declared as "declare function ... external" in a XQuery expression.

Public OnImportModule: TXQImportModuleEvent;

Event called to import a XQuery module that has not previously be defined

Public OnTrace: TXQTraceEvent;

Event called by fn:trace

Public OnCollection: TXQEvaluateVariableEvent;

Event called by fn:collection

Public OnParseDoc: TXQParseDocEvent;

Event called by fn:doc (if nil, a default xml parser is used)

Public ParsingOptions: TXQParsingOptions;
 
Public GlobalNamespaces: TNamespaceList;

Globally defined namespaces

Public AutomaticallyRegisterParsedModules: boolean;
 

Methods

Public procedure clear;

Clears all data.

Public function parseXPath2(s:string; sharedContext: TXQStaticContext = nil): IXQuery;

Parses a new XPath 2.0 expression and stores it in tokenized form.

Public function parseXQuery1(s:string; sharedContext: TXQStaticContext = nil): IXQuery;

Parses a new XQuery 1.0 expression and stores it in tokenized form.

Public function parseXPath3(s:string; sharedContext: TXQStaticContext = nil): IXQuery;

Parses a new XPath 3.0 expression and stores it in tokenized form. Work in progress, only a small set of 3.0 statements is supported

Public function parseXQuery3(s:string; sharedContext: TXQStaticContext = nil): IXQuery;

Parses a new XQuery 3.0 expression and stores it in tokenized form. Work in progress, only a small set of 3.0 statements is supported

Public function parseCSS3(s:string): IXQuery;

Parses a new CSS 3.0 Selector expression and stores it in tokenized form.

Public function parseQuery(s:string; model: TXQParsingModel; sharedContext: TXQStaticContext = nil): IXQuery;

Parses a new expression and stores it in tokenized form.

Public function evaluate(const context: TXQEvaluationContext): IXQValue;
 
Public function evaluate(const contextItem: IXQValue): IXQValue;

Evaluates a previously parsed query and returns its value as IXQValue

Public function evaluate(tree:TTreeNode = nil): IXQValue;

Evaluates a previously parsed query and returns its value as IXQValue

Public constructor create;
 
Public destructor Destroy; override;
 
Public function evaluateXPath2(expression: string; tree:TTreeNode = nil): IXQValue;

Evaluates an XPath 2.0 expression with a certain tree element as current node.

Public function evaluateXPath2(expression: string; const contextItem: IXQValue): IXQValue;
 
Public function evaluateXQuery1(expression: string; tree:TTreeNode = nil): IXQValue;

Evaluates an XQuery 1.0 expression with a certain tree element as current node.

Public function evaluateXQuery1(expression: string; const contextItem: IXQValue): IXQValue;
 
Public function evaluateXPath3(expression: string; tree:TTreeNode = nil): IXQValue;

Evaluates an XPath 3.0 expression with a certain tree element as current node. Work in progress, only a small set of 3.0 statements is supported

Public function evaluateXPath3(expression: string; const contextItem: IXQValue): IXQValue;
 
Public function evaluateXQuery3(expression: string; tree:TTreeNode = nil): IXQValue;

Evaluates an XQuery 3.0 expression with a certain tree element as current node. Work in progress, only a small set of 3.0 statements is supported

Public function evaluateXQuery3(expression: string; const contextItem: IXQValue): IXQValue;
 
Public function evaluateCSS3(expression: string; tree:TTreeNode = nil): IXQValue;

Evaluates an CSS 3 Selector expression with a certain tree element as current node.

Public function evaluateCSS3(expression: string; const contextItem: IXQValue): IXQValue;
 
Public class function evaluateStaticXPath2(expression: string; tree:TTreeNode = nil): IXQValue;

Evaluates an expression with a certain tree element as current node.

Public class function evaluateStaticXPath2(expression: string; const contextItem: IXQValue): IXQValue;
 
Public class function evaluateStaticXPath3(expression: string; tree:TTreeNode = nil): IXQValue;
 
Public class function evaluateStaticXPath3(expression: string; const contextItem: IXQValue): IXQValue;
 
Public class function evaluateStaticXQuery1(expression: string; tree:TTreeNode = nil): IXQValue;
 
Public class function evaluateStaticXQuery1(expression: string; const contextItem: IXQValue): IXQValue;
 
Public class function evaluateStaticXQuery3(expression: string; tree:TTreeNode = nil): IXQValue;
 
Public class function evaluateStaticXQuery3(expression: string; const contextItem: IXQValue): IXQValue;
 
Public class function evaluateStaticCSS3(expression: string; tree:TTreeNode = nil): IXQValue;

Evaluates an expression with a certain tree element as current node.

Public procedure registerModule(module: IXQuery);

Registers an XQuery module. A XQuery module is created by parsing (not evaluating) a XQuery expression that contains a "module" declaration

Public function findModule(const namespaceURL: string): TXQuery;

Finds a certain registered XQuery module

Public class function findNativeModule(const ns: string): TXQNativeModule;

Finds a native module.

Public class procedure registerCollation(const collation: TXQCollation);

Registers a collation for custom string comparisons

Public class function getCollation(id:string; base: string): TXQCollation;

Returns the collation for an url id

Public class procedure registerNativeModule(const module: TXQNativeModule);
 
Public class function collationsInternal: TStringList;
 
Public function getEvaluationContext(staticContextOverride: TXQStaticContext = nil): TXQEvaluationContext;
 

Properties

Public property ExternalDocumentsCacheInternal: TStringList read FExternalDocuments write FExternalDocuments;
 
Public property LastQuery: IXQuery read FLastQuery;

Last parsed query


Generated by PasDoc 0.11.0 on 2015-06-29 00:55:45