SaxonC 12.7.0
Saxon Processor library for C/C++, PHP and Python
Loading...
Searching...
No Matches
Public Member Functions | List of all members
XPathProcessor Class Reference

An XPathProcessor represents a factory to compile, load and execute XPath expressions. More...

#include <XPathProcessor.h>

Public Member Functions

 XPathProcessor ()
 Default constructor.
 
 XPathProcessor (SaxonProcessor *proc, std::string cwd="")
 Constructor with the SaxonProcessor supplied.
 
 XPathProcessor (const XPathProcessor &other)
 XPathProcessor copy constructor.
 
void setBaseURI (const char *uriStr)
 Set the static base URI for XPath expressions compiled using this XPathProcessor.
 
const char * getBaseURI ()
 Get the static base URI for XPath expressions compiled using this XPathProcessor.
 
XdmValueevaluate (const char *xpathStr, const char *encoding=nullptr)
 Compile and evaluate an XPath expression.
 
XdmItemevaluateSingle (const char *xpathStr, const char *encoding=nullptr)
 Compile and evaluate an XPath expression; the result is expected to be a single XdmItem or nullptr.
 
void setContextItem (XdmItem *item)
 Set the context item for the expression.
 
void setcwd (const char *cwd)
 Set the current working directory.
 
const char * getcwd ()
 Get the current working directory set on this XPathProcessor.
 
void setContextFile (const char *filename)
 Set the context item from file.
 
bool effectiveBooleanValue (const char *xpathStr, const char *encoding=nullptr)
 Evaluate the XPath expression, returning the effective boolean value of the result.
 
void setParameter (const char *name, XdmValue *value, bool withParam=true)
 Set the value of a parameter used in the XPath expression.
 
bool removeParameter (const char *name)
 Remove a parameter (name, value) pair.
 
void setProperty (const char *name, const char *value)
 Set a configuration property specific to the XPath processor in use.
 
const char * getProperty (const char *name)
 Get the value of a configuration property specified on the XPath processor in use.
 
void declareNamespace (const char *prefix, const char *uri)
 Declare a namespace binding as part of the static context for XPath expressions compiled using this XPathProcessor.
 
void declareVariable (const char *name)
 Declare a variable as part of the static context for XPath expressions compiled using this XPathProcessor.
 
void setLanguageVersion (const char *version)
 Say whether an XPath 2.0, XPath 3.0, XPath 3.1 or XPath 4.0 processor is required.
 
void setBackwardsCompatible (bool option)
 Say whether XPath 1.0 backwards compatibility mode is to be used.
 
void setCaching (bool caching)
 Say whether the compiler should maintain a cache of compiled expressions.
 
void setUnprefixedElementMatchingPolicy (UnprefixedElementMatchingPolicy policy)
 Set the policy for matching unprefixed element names in XPath expressions.
 
UnprefixedElementMatchingPolicy convertEnumPolicy (int n)
 Convert an int into an UnprefixedElementMatchingPolicy.
 
UnprefixedElementMatchingPolicy getUnprefixedElementMatchingPolicy ()
 Get the policy for matching unprefixed element names in XPath expressions.
 
void importSchemaNamespace (const char *uri)
 Import a schema namespace.
 
XdmValuegetParameter (const char *name, bool withParam=true)
 Get the value of a parameter.
 
std::map< std::string, XdmValue * > & getParameters ()
 Get all parameters as a std::map.
 
std::map< std::string, std::string > & getProperties ()
 Get all configuration properties specified on the processor as a std::map.
 
void clearParameters (bool deleteValues=false)
 Clear parameter values set.
 
void clearProperties ()
 Clear property values set.
 
bool exceptionOccurred ()
 Deprecated.
 
void exceptionClear ()
 Deprecated.
 
const char * getErrorMessage ()
 Deprecated.
 
const char * getErrorCode ()
 Deprecated.
 
SaxonApiExceptiongetException ()
 Deprecated.
 
SaxonProcessorgetSaxonProcessor ()
 Get the SaxonProcessor which created this XPathProcessor.
 

Detailed Description

An XPathProcessor represents a factory to compile, load and execute XPath expressions.

Constructor & Destructor Documentation

◆ XPathProcessor() [1/3]

XPathProcessor::XPathProcessor ( )

Default constructor.

Creates a Saxon-HE XPath processor.

◆ XPathProcessor() [2/3]

XPathProcessor::XPathProcessor ( SaxonProcessor * proc,
std::string cwd = "" )

Constructor with the SaxonProcessor supplied.

Parameters
proc- pointer to the SaxonProcessor object
cwd- the current working directory
Exceptions
SaxonApiException

◆ XPathProcessor() [3/3]

XPathProcessor::XPathProcessor ( const XPathProcessor & other)

XPathProcessor copy constructor.

Parameters
other- XPathProcessor

Member Function Documentation

◆ clearParameters()

void XPathProcessor::clearParameters ( bool deleteValues = false)

Clear parameter values set.

Default behaviour (false) is to leave XdmValues in memory. Individual pointers to XdmValue objects have to be deleted in the calling program.

Parameters
deleteValues- if true then XdmValues are deleted

◆ convertEnumPolicy()

UnprefixedElementMatchingPolicy XPathProcessor::convertEnumPolicy ( int n)
inline

Convert an int into an UnprefixedElementMatchingPolicy.

To be used with the setUnprefixedElementMatchingPolicy method.

Parameters
n- the int representing the policy

◆ declareNamespace()

void XPathProcessor::declareNamespace ( const char * prefix,
const char * uri )

Declare a namespace binding as part of the static context for XPath expressions compiled using this XPathProcessor.

Parameters
prefix- the namespace prefix. If the value is a zero-length string, this method sets the default namespace for elements and types.
uri- the namespace URI. It is possible to specify a zero-length string to "undeclare" a namespace; in this case the prefix will not be available for use, except in the case where the prefix is also a zero length string, in which case the absence of a prefix implies that the name is in no namespace.
Exceptions
SaxonApiExceptionif either the prefix or uri is nullptr

◆ declareVariable()

void XPathProcessor::declareVariable ( const char * name)

Declare a variable as part of the static context for XPath expressions compiled using this XPathProcessor.

It is an error for the XPath expression to refer to a variable unless it has been declared. This method declares the existence of the variable, but it does not bind any value to the variable; that is done later, when the XPath expression is evaluated. The variable is allowed to have any type (that is, the required type is item()*).

Parameters
name- the name of the parameter, as a string. For a namespaced name use clark notation i.e. "{uri}local"

◆ effectiveBooleanValue()

bool XPathProcessor::effectiveBooleanValue ( const char * xpathStr,
const char * encoding = nullptr )

Evaluate the XPath expression, returning the effective boolean value of the result.

Parameters
xpathStr- the XPath expression supplied as a character string
encoding- the encoding of the string. If not specified then the platform default encoding is used.
Returns
The effective boolean value of the result
Exceptions
SaxonApiException

◆ evaluate()

XdmValue * XPathProcessor::evaluate ( const char * xpathStr,
const char * encoding = nullptr )

Compile and evaluate an XPath expression.

Parameters
xpathStr- the XPath expression supplied as a character string
encoding- the encoding of the string. If not specified then the platform default encoding is used.
Returns
An XdmValue representing the result of evaluating the expression or nullptr if the expression returns an empty sequence. The caller is responsible for memory deallocation using delete.
Exceptions
SaxonApiException

◆ evaluateSingle()

XdmItem * XPathProcessor::evaluateSingle ( const char * xpathStr,
const char * encoding = nullptr )

Compile and evaluate an XPath expression; the result is expected to be a single XdmItem or nullptr.

Parameters
xpathStr- the XPath expression supplied as a character string
encoding- the encoding of the string. If not specified then the platform default encoding is used.
Returns
An XdmItem representing the result of evaluating the expression or nullptr if the expression returns an empty sequence. If the expression returns a sequence of more than one item, any items after the first are ignored. The caller is responsible for memory deallocation using delete.
Exceptions
SaxonApiException

◆ exceptionClear()

void XPathProcessor::exceptionClear ( )

Deprecated.

Clear any thrown exceptions

Deprecated
From 12.1 this method is no longer used, since exceptions are now thrown.

◆ exceptionOccurred()

bool XPathProcessor::exceptionOccurred ( )

Deprecated.

Checks for pending exceptions without creating a local reference to the exception object

Returns
True when there is a pending exception; otherwise false
Deprecated
From 12.1 this method is no longer used, since exceptions are now thrown.

◆ getBaseURI()

const char * XPathProcessor::getBaseURI ( )

Get the static base URI for XPath expressions compiled using this XPathProcessor.

Note that memory deallocation is handled internally.

Returns
The static base URI as a string

◆ getcwd()

const char * XPathProcessor::getcwd ( )

Get the current working directory set on this XPathProcessor.

Memory deallocation is handled internally.

Returns
Current working directory

◆ getErrorCode()

const char * XPathProcessor::getErrorCode ( )

Deprecated.

Get the first error code if there are any errors. After the execution of the XPath expression there may be a number of errors reported against it.

Returns
The error code of the exception
Deprecated
From 12.1 this method is no longer used, since exceptions are now thrown.

◆ getErrorMessage()

const char * XPathProcessor::getErrorMessage ( )

Deprecated.

Get the first error message if there are any errors. An XPath expression may have a number of errors reported against it.

Returns
The message of the exception
Deprecated
From 12.1 this method is no longer used, since exceptions are now thrown.

◆ getException()

SaxonApiException * XPathProcessor::getException ( )

Deprecated.

Get the SaxonApiException object created when we have an error. After the execution of the processor if there is an error then a SaxonApiException is created.

Returns
The SaxonApiException object if there is an exception thrown, or nullptr otherwise
Deprecated
From 12.1 this method is no longer used, since exceptions are now thrown.

◆ getParameter()

XdmValue * XPathProcessor::getParameter ( const char * name,
bool withParam = true )

Get the value of a parameter.

Parameters
name- the name of the parameter
withParam- internal use only
Returns
The value of the parameter as an XdmValue

◆ getProperty()

const char * XPathProcessor::getProperty ( const char * name)

Get the value of a configuration property specified on the XPath processor in use.

Memory deallocation is handled internally.

Parameters
name- the name of the property
Returns
Value of the property or nullptr if the property is not found. Memory deallocation is handled internally.

◆ getUnprefixedElementMatchingPolicy()

UnprefixedElementMatchingPolicy XPathProcessor::getUnprefixedElementMatchingPolicy ( )

Get the policy for matching unprefixed element names in XPath expressions.

Returns
The policy being used

◆ importSchemaNamespace()

void XPathProcessor::importSchemaNamespace ( const char * uri)

Import a schema 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. 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(String, String) method.

Parameters
uri- the schema namespace to be imported. To import declarations in a no-namespace schema, supply a zero-length string.

◆ removeParameter()

bool XPathProcessor::removeParameter ( const char * name)

Remove a parameter (name, value) pair.

Parameters
name- the name of the parameter
Returns
Outcome of the removal

◆ setBackwardsCompatible()

void XPathProcessor::setBackwardsCompatible ( bool option)

Say whether XPath 1.0 backwards compatibility mode is to be used.

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).

Parameters
option- true if XPath 1.0 backwards compatibility is to be enabled, false if it is to be disabled.

◆ setBaseURI()

void XPathProcessor::setBaseURI ( const char * uriStr)

Set the static base URI for XPath expressions compiled using this XPathProcessor.

The base URI is part of the static context, and is used to resolve any relative URIs appearing within an XPath expression, for example a relative URI passed as an argument to the doc() function. If no static base URI is supplied, then the current working directory is used.

Parameters
uriStr- the static base URI

◆ setCaching()

void XPathProcessor::setCaching ( bool caching)

Say whether the compiler should maintain a cache of compiled expressions.

Parameters
caching- if set to true, caching of compiled expressions is enabled. If set to false, any existing cache is cleared, and future compiled expressions will not be cached until caching is re-enabled. The cache is also cleared (but without disabling future caching) if any method is called that changes the static context for compiling expressions, for example declareVariable(QName) or declareNamespace(String, String).

◆ setContextItem()

void XPathProcessor::setContextItem ( XdmItem * item)

Set the context item for the expression.

Parameters
item- the initial context item

◆ setcwd()

void XPathProcessor::setcwd ( const char * cwd)

Set the current working directory.

Parameters
cwd- current working directory

◆ setLanguageVersion()

void XPathProcessor::setLanguageVersion ( const char * version)

Say whether an XPath 2.0, XPath 3.0, XPath 3.1 or XPath 4.0 processor is required.

Set the language version for the XPath compiler.

Parameters
versionOne of the values 1.0, 2.0, 3.0, 3.05, 3.1, 4.0. Setting the option to 1.0 requests an XPath 2.0 processor running in 1.0 compatibility mode; this is equivalent to setting the language version to 2.0 and backwards compatibility mode to true. Requesting "3.05" gives XPath 3.0 plus the extensions defined in the XSLT 3.0 specification (map types and map constructors).

◆ setParameter()

void XPathProcessor::setParameter ( const char * name,
XdmValue * value,
bool withParam = true )

Set the value of a parameter used in the XPath expression.

Parameters
name- the name of the parameter, as a string. For a namespaced name use clark notation i.e. "{uri}local"
value- the value of the parameter, or nullptr to clear a previously set value
withParam- internal use only

◆ setProperty()

void XPathProcessor::setProperty ( const char * name,
const char * value )

Set a configuration property specific to the XPath processor in use.

XPathProcessor: set serialization properties (names start with '!' i.e. name "!method" -> "xml"), 'o':outfile name, 's': context item supplied as file name

Parameters
name- the name of the property
value- the value of the property

◆ setUnprefixedElementMatchingPolicy()

void XPathProcessor::setUnprefixedElementMatchingPolicy ( UnprefixedElementMatchingPolicy policy)

Set the policy for matching unprefixed element names in XPath expressions.

Use the convertEnumPolicy method to create an UnprefixedElementMatchingPolicy value.

Parameters
policy- the policy to be used, possible values: DEFAULT_NAMESPACE = 0, ANY_NAMESPACE = 1 or DEFAULT_NAMESPACE_OR_NONE = 2

The documentation for this class was generated from the following files: