SaxonC 12.5
Saxon Processor library for C/C++, PHP and Python
|
#include <XPathProcessor.h>
Public Member Functions | |
XPathProcessor () | |
Default constructor. | |
XPathProcessor (SaxonProcessor *proc, std::string cwd="") | |
Constructor with the SaxonProcessor supplied. | |
XPathProcessor (const XPathProcessor &other) | |
void | setBaseURI (const char *uriStr) |
const char * | getBaseURI () |
XdmValue * | evaluate (const char *xpathStr, const char *encoding=nullptr) |
Compile and evaluate an XPath expression. | |
XdmItem * | evaluateSingle (const char *xpathStr, const char *encoding=nullptr) |
void | setContextItem (XdmItem *item) |
void | setcwd (const char *cwd) |
void | setContextFile (const char *filename) |
bool | effectiveBooleanValue (const char *xpathStr, const char *encoding=nullptr) |
void | setParameter (const char *name, XdmValue *value, bool withParam=true) |
bool | removeParameter (const char *name) |
void | setProperty (const char *name, const char *value) |
Set a property specific to the processor in use. | |
void | declareNamespace (const char *prefix, const char *uri) |
void | declareVariable (const char *name) |
void | setLanguageVersion (const char *version) |
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) |
UnprefixedElementMatchingPolicy | getUnprefixedElementMatchingPolicy () |
! Get the policy for matching unprefixed element names in XPath expressions | |
void | importSchemaNamespace (const char *uri) |
Import a schema namespace. | |
XdmValue * | getParameter (const char *name, bool withParam=true) |
std::map< std::string, XdmValue * > & | getParameters () |
std::map< std::string, std::string > & | getProperties () |
void | clearParameters (bool deleteValues=false) |
void | clearProperties () |
bool | exceptionOccurred () |
void | exceptionClear () |
Clear any exception thrown. | |
const char * | getErrorMessage () |
Get the first error message if there are any errors. | |
const char * | getErrorCode () |
Get the first error code if there are any errors. | |
SaxonApiException * | getException () |
Get the SaxonApiException object created when we have an error. | |
An XPathProcessor
represents a factory to compile, load and execute XPath expressions.
XPathProcessor::XPathProcessor | ( | ) |
Default constructor.
Creates a Saxon-HE XPath product
XPathProcessor::XPathProcessor | ( | SaxonProcessor * | proc, |
std::string | cwd = "" ) |
Constructor with the SaxonProcessor supplied.
proc | - Pointer to the SaxonProcessor object |
cwd | - The current working directory |
SaxonApiException |
XPathProcessor::XPathProcessor | ( | const XPathProcessor & | other | ) |
XPathProcessor copy constructor.
other | - XPathProcessor |
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.
deleteValues | - if true then XdmValues are deleted |
void XPathProcessor::clearProperties | ( | ) |
Clear property values set
|
inline |
Convert an int into an UnprefixedElementMatchingPolicy
n | - the int representing the policy |
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 XPathCompiler
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. Assume the prefix or uri is nullptr. |
void XPathProcessor::declareVariable | ( | const char * | name | ) |
Declare a variable as part of the static context for XPath expressions compiled using this XPathCompiler
. 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()*
).
name | The name of the variable, expressions as a clark name string |
bool XPathProcessor::effectiveBooleanValue | ( | const char * | xpathStr, |
const char * | encoding = nullptr ) |
Evaluate the XPath expression, returning the effective boolean value of the result.
xpathStr | - supplied as a character string |
encoding | - the encoding of the string. If not specified then the platform default encoding is used. |
SaxonApiException |
XdmValue * XPathProcessor::evaluate | ( | const char * | xpathStr, |
const char * | encoding = nullptr ) |
Compile and evaluate an XPath expression.
xpathStr | - supplied as a character string |
encoding | - the encoding of the string. If not specified then the platform default encoding is used. |
SaxonApiException |
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
xpathStr | - supplied as a character string |
encoding | - the encoding of the string. If not specified then the platform default encoding is used. |
SaxonApiException |
bool XPathProcessor::exceptionOccurred | ( | ) |
Checks for pending exceptions without creating a local reference to the exception object
const char * XPathProcessor::getBaseURI | ( | ) |
Get the static base URI for XPath expressions compiled using this XPathCompiler.
const char * XPathProcessor::getErrorCode | ( | ) |
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.
const char * XPathProcessor::getErrorMessage | ( | ) |
Get the first error message if there are any errors.
An XPath expression may have a number of errors reported against it.
SaxonApiException * XPathProcessor::getException | ( | ) |
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. NULL returned if there is no error.
XdmValue * XPathProcessor::getParameter | ( | const char * | name, |
bool | withParam = true ) |
Get a parameter value by name
name | - Specified parameter name to get |
withParam | Internal use only |
std::map< std::string, XdmValue * > & XPathProcessor::getParameters | ( | ) |
Get all parameters as a std::map
std::map< std::string, std::string > & XPathProcessor::getProperties | ( | ) |
Get all properties as a std::map
UnprefixedElementMatchingPolicy XPathProcessor::getUnprefixedElementMatchingPolicy | ( | ) |
! Get the policy for matching unprefixed element names in XPath expressions
void XPathProcessor::importSchemaNamespace | ( | const char * | uri | ) |
Import a schema namespace.
Here we 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.
uri | The schema namespace to be imported. To import declarations in a no-namespace schema, supply a zero-length string. |
bool XPathProcessor::removeParameter | ( | const char * | name | ) |
Remove a parameter (name, value) pair
name | of the parameter |
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).
option | true if XPath 1.0 backwards compatibility is to be enabled, false if it is to be disabled. |
void XPathProcessor::setBaseURI | ( | const char * | uriStr | ) |
Set the static base URI for XPath expressions compiled using this XPathCompiler. 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.
uriStr |
void XPathProcessor::setCaching | ( | bool | caching | ) |
Say whether the compiler should maintain a cache of compiled expressions.
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). |
void XPathProcessor::setContextFile | ( | const char * | filename | ) |
Set the context item from file
void XPathProcessor::setContextItem | ( | XdmItem * | item | ) |
Set the context item
void XPathProcessor::setcwd | ( | const char * | cwd | ) |
set the current working directory
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.
version | One 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). |
void XPathProcessor::setParameter | ( | const char * | name, |
XdmValue * | value, | ||
bool | withParam = true ) |
Set a parameter value used in the query
name | of the parameter, as a string. For namespaced parameter use the JAXP solution i.e. "{uri}name" |
value | of the query parameter, or nullptr to clear a previously set value |
withParam | Internal use only |
void XPathProcessor::setProperty | ( | const char * | name, |
const char * | value ) |
Set a property specific to the 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
name | of the property |
value | of the property |
void XPathProcessor::setUnprefixedElementMatchingPolicy | ( | UnprefixedElementMatchingPolicy | policy | ) |
Set the policy for matching unprefixed element names in XPath expressions.
policy | the policy to be used, possible values: DEFAULT_NAMESPACE = 0, ANY_NAMESPACE = 1 or DEFAULT_NAMESPACE_OR_NONE = 2 |