Class DocumentBuilder
Class DomDestination
Class DynamicContext
Class DynamicError
Class EmptyEnumerator
Class ExtensionFunctionCall
Class NullDestination
Class Processor
Class QName
Class SchemaManager
Class SchemaValidator
Class Serializer
Class StaticContext
Class StaticError
Class TextWriterDestination
Class XPathCompiler
Class XPathExecutable
Class XPathSelector
Class XQueryCompiler
Class XQueryEvaluator
Class XQueryExecutable
Class XdmAnyFunctionType
Class XdmAnyItemType
Class XdmAnyNodeType
Class XdmAtomicType
Class XdmAtomicValue
Class XdmDestination
Class XdmEmptySequence
Class XdmFunctionItem
Class XdmItem
Class XdmItemType
Class XdmNode
Class XdmNodeKind
Class XdmSequenceType
Class XdmValue
Class XmlDestination
Class XsltCompiler
Class XsltExecutable
Class XsltTransformer
Enum RecoveryPolicy
Enum SchemaValidationMode
Enum TreeModel
Enum WhitespacePolicy
Enum XdmAxis
Interface IMessageListener
Interface IQueryResolver
Interface IResultDocumentHandler
Interface IXdmEnumerator
Interface IXmlLocation
Interface SchemaResolver
public class XPathCompiler
An XPathCompiler object allows XPath queries to be compiled. The compiler holds information that represents the static context for the expression.
To construct an XPathCompiler, use the factory method
newXPathCompiler
on the Processor
object.
An XPathCompiler may be used repeatedly to compile multiple queries. Any changes made to the XPathCompiler (that is, to the static context) do not affect queries that have already been compiled. An XPathCompiler may be used concurrently in multiple threads, but it should not then be modified once initialized.
The XPathCompiler
has the ability to maintain a cache of compiled
expressions. This is active only if enabled by setting the Caching
property.
If caching is enabled, then the compiler will recognize an attempt to compile
the same expression twice, and will avoid the cost of recompiling it. The cache
is emptied by any method that changes the static context for subsequent expressions,
for example, by setting the BaseUri
property. Unless the cache is emptied,
it grows indefinitely: compiled expressions are never discarded.
Property Summary | |
---|---|
Processor |
Processor Get the Processor from which this XPathCompiler was constructed |
Boolean |
AllowUndeclaredVariables
This property indicates whether the XPath expression may contain references to variables
that have not been
explicitly declared by calling |
Boolean |
SchemaAware Say whether XPath expressions compiled using this XPathCompiler are schema-aware. They will automatically be schema-aware if the method {@link #importSchemaNamespace(String)} is called. An XPath expression must be marked as schema-aware if it is to handle typed (validated) input documents. |
string |
XPathLanguageVersion This property indicates which version of XPath language syntax is accepted. The default value is "1.0". This property must be set to "3.0" before compiling a query that uses XPath 3.0 (formerly known as XPath 2.1) syntax. |
XdmItemType |
ContextItemType The required context item type for the expression. This is used for optimizing the expression at compile time, and to check at run-time that the value supplied for the context item is the correct type. |
String |
BaseUri
The base URI of the expression, which forms part of the static context
of the expression. This is used for resolving any relative URIs appearing
within the expression, for example in references to library modules, schema
locations, or as an argument to the |
Boolean |
BackwardsCompatible XPath 1.0 Backwards Compatibility Mode. If true, backwards compatibility mode is set. In backwards compatibility mode, more implicit type conversions are allowed in XPath expressions, for example it is possible to compare a number with a string. The default is false (backwards compatibility mode is off). |
Boolean |
Caching XPath 1.0 Backwards Compatibility Mode. If true, backwards compatibility mode is set. In backwards compatibility mode, more implicit type conversions are allowed in XPath expressions, for example it is possible to compare a number with a string. The default is false (backwards compatibility mode is off). |
Method Summary | |
---|---|
void |
DeclareCollation(System.Uri uri, System.Globalization.CompareInfo compareInfo, System.Globalization.CompareOptions options, bool isDefault)
Create a collation based on a given |
void |
DeclareNamespace(string prefix, string uri) Declare a namespace for use by the XPath expression. |
string |
GetNamespaceURI() |
void |
ImportSchemaNamespace(string uri) Import schema definitions for a specified namespace. That is, add the element and attribute declarations and type definitions contained in a given namespace to the static context for the XPath expression. |
void |
SetDecimalFormatProperty(QName format, string property, string value)
Sets a property of a selected decimal format, for use by the |
void |
DeclareVariable(QName name)
Declare a variable for use by the XPath expression. If the expression
refers to any variables, then they must be declared here, unless the
|
XPathExecutable |
Compile(string source) Compile an expression supplied as a String. |
XdmValue |
Evaluate(string expression, XdmItem contextItem) Compile and execute an expression supplied as a String, with a given context item. |
XdmItem |
EvaluateSingle(string expression, XdmItem contextItem) Compile and execute an expression supplied as a String, with a given context item, where the expression is expected to return a single item as its result |
Property Detail |
---|
public Processor Processor {get; set; }
Get the Processor from which this XPathCompiler was constructed
public Boolean AllowUndeclaredVariables {get; set; }
This property indicates whether the XPath expression may contain references to variables
that have not been
explicitly declared by calling DeclareVariable
. The property is false by default (that is, variables
must be declared).
If undeclared variables are permitted, then it is possible to determine after compiling
the expression which
variables it refers to by calling the method EnumerateExternalVariables
on the XPathExecutable
object.
public Boolean SchemaAware {get; set; }
Say whether XPath expressions compiled using this XPathCompiler are schema-aware. They will automatically be schema-aware if the method {@link #importSchemaNamespace(String)} is called. An XPath expression must be marked as schema-aware if it is to handle typed (validated) input documents.
public string XPathLanguageVersion {get; set; }
This property indicates which version of XPath language syntax is accepted. The default value is "1.0". This property must be set to "3.0" before compiling a query that uses XPath 3.0 (formerly known as XPath 2.1) syntax.
Support for XPath 3.0 is currently limited: for details see the Saxon documentation.
Property added in Saxon 9.4
public XdmItemType ContextItemType {get; set; }
The required context item type for the expression. This is used for optimizing the expression at compile time, and to check at run-time that the value supplied for the context item is the correct type.
public String BaseUri {get; set; }
The base URI of the expression, which forms part of the static context
of the expression. This is used for resolving any relative URIs appearing
within the expression, for example in references to library modules, schema
locations, or as an argument to the doc()
function.
public Boolean BackwardsCompatible {get; set; }
XPath 1.0 Backwards Compatibility Mode. If true, backwards compatibility mode is set. In backwards compatibility mode, more implicit type conversions are allowed in XPath expressions, for example it is possible to compare a number with a string. The default is false (backwards compatibility mode is off).
public Boolean Caching {get; set; }
XPath 1.0 Backwards Compatibility Mode. If true, backwards compatibility mode is set. In backwards compatibility mode, more implicit type conversions are allowed in XPath expressions, for example it is possible to compare a number with a string. The default is false (backwards compatibility mode is off).
Method Detail |
---|
public void DeclareCollation(System.Uri uri, System.Globalization.CompareInfo compareInfo, System.Globalization.CompareOptions options, bool isDefault)
Create a collation based on a given CompareInfo
and CompareOptions
uri
-
compareInfo
-
CompareInfo
, which determines the language-specific
collation rules to be used
options
-
isDefault
-
public void DeclareNamespace(string prefix, string uri)
Declare a namespace for use by the XPath expression.
Parameters:prefix
-
uri
-
public string GetNamespaceURI()
public void ImportSchemaNamespace(string uri)
Import schema definitions for a specified namespace. That is, add the element and attribute declarations and type definitions contained in a given namespace to the static context for the XPath expression.
This method will not cause the schema to be loaded. That must be done separately,
using the
SchemaManager
}. This method will not fail if the schema has not been loaded (but in that case
the set of declarations and definitions made available to the XPath expression is
empty). The schema
document for the specified namespace may be loaded before or after this method is
called.
This method does not bind a prefix to the namespace. That must be done separately,
using the
declareNamespace
method.
uri
-
public void SetDecimalFormatProperty(QName format, string property, string value)
Sets a property of a selected decimal format, for use by the format-number
function.
This method checks that the value is valid for the particular property, but it does not check that all the values for the decimal format are consistent (for example, that the decimal separator and grouping separator have different values). This consistency check is performed only when the decimal format is used.
Parameters:format
-
format-number
.
property
-
value
-
public void DeclareVariable(QName name)
Declare a variable for use by the XPath expression. If the expression
refers to any variables, then they must be declared here, unless the
AllowUndeclaredVariables
property has been set to true.
name
-
QName
public XPathExecutable Compile(string source)
Compile an expression supplied as a String.
Parameters:source
-
XPathExecutable
which represents the compiled xpath expression object.
The XPathExecutable may be run as many times as required, in the same or a different
thread. The XPathExecutable
is not affected by any changes made to the XPathCompiler
once it has been compiled.
public XdmValue Evaluate(string expression, XdmItem contextItem)
Compile and execute an expression supplied as a String, with a given context item.
Parameters:expression
-
contextItem
-
XdmValue
which is the result of evaluating the XPath expression.
public XdmItem EvaluateSingle(string expression, XdmItem contextItem)
Compile and execute an expression supplied as a String, with a given context item, where the expression is expected to return a single item as its result
Parameters:expression
-
contextItem
-
XdmItem
which is the result of evaluating the XPath expression. If the expression returns
an empty sequence,
then null. If the expression returns a sequence containing more than one item, then
the first
item in the result.