SaxonC 12.7.0
Saxon Processor library for C/C++, PHP and Python
Loading...
Searching...
No Matches
XPathProcessor.h
1
2// Copyright (c) 2022 - 2025 Saxonica Limited.
3// This Source Code Form is subject to the terms of the Mozilla Public License,
4// v. 2.0. If a copy of the MPL was not distributed with this file, You can
5// obtain one at http://mozilla.org/MPL/2.0/. This Source Code Form is
6// "Incompatible With Secondary Licenses", as defined by the Mozilla Public
7// License, v. 2.0.
9
10#ifndef SAXON_XPATH_H
11#define SAXON_XPATH_H
12
13#include "saxonc_export.h"
14#include "saxonc/SaxonProcessor.h"
15//#include "XdmValue.h"
16//#include "XdmItem.h"
17
18#include <string>
19
20class SaxonProcessor;
22class XdmValue;
23class XdmItem;
24
25enum class SAXONC_EXPORT UnprefixedElementMatchingPolicy {
26
34 DEFAULT_NAMESPACE = 0,
40 ANY_NAMESPACE = 1,
58 DEFAULT_NAMESPACE_OR_NONE = 2
59};
60
64class SAXONC_EXPORT XPathProcessor {
65public:
72
74
81 XPathProcessor(SaxonProcessor *proc, std::string cwd = "");
82
87 XPathProcessor(const XPathProcessor &other);
88
98 void setBaseURI(const char *uriStr);
99
105 const char *getBaseURI();
106
117 XdmValue *evaluate(const char *xpathStr, const char *encoding = nullptr);
118
131 XdmItem *evaluateSingle(const char *xpathStr, const char *encoding = nullptr);
132
136 void setContextItem(XdmItem *item);
137
142 void setcwd(const char *cwd);
143
149 const char * getcwd();
150
153 void setContextFile(const char *filename);
154
163 bool effectiveBooleanValue(const char *xpathStr,
164 const char *encoding = nullptr);
165
176 void setParameter(const char *name, XdmValue *value, bool withParam=true);
177
184 bool removeParameter(const char *name);
185
194 void setProperty(const char *name, const char *value);
195
201 const char * getProperty(const char *name);
202
214 void declareNamespace(const char *prefix, const char *uri);
215
228 void declareVariable(const char *name);
229
241 void setLanguageVersion(const char *version);
242
253 void setBackwardsCompatible(bool option);
254
265 void setCaching(bool caching);
266
274 void
275 setUnprefixedElementMatchingPolicy(UnprefixedElementMatchingPolicy policy);
276
283 UnprefixedElementMatchingPolicy convertEnumPolicy(int n) {
284 return static_cast<UnprefixedElementMatchingPolicy>(n);
285 }
286
291 UnprefixedElementMatchingPolicy getUnprefixedElementMatchingPolicy();
292
308 void importSchemaNamespace(const char *uri);
309
316 XdmValue *getParameter(const char *name, bool withParam=true);
317
321 std::map<std::string, XdmValue *> &getParameters();
322
326 std::map<std::string, std::string> &getProperties();
327
335 void clearParameters(bool deleteValues = false);
336
340 void clearProperties();
341
342
349 bool exceptionOccurred();
350
355 void exceptionClear();
356
363 const char *getErrorMessage();
364
372 const char *getErrorCode();
373
381 SaxonApiException *getException();
382
387
388private:
389 void createException(const char *message = nullptr);
390
391
392 SaxonProcessor *proc;
393 std::string cwdXP;
394 char *xp_baseURI;
395 // jclass cppClass; /*!< Reference to the XPathProcessor Java class under JNI
396 // */
397 int64_t cppXP;
398 std::map<std::string, XdmValue *>
399 parameters;
401 std::map<std::string, std::string>
402 properties;
405 *exception;
406 UnprefixedElementMatchingPolicy unprefixedElementPolicy;
407};
408
409#endif /* SAXON_XPATH_H */
SAXONC_EXPORT void setParameter(sxnc_parameter **parameters, int *parLen, int *parCap, const char *name, sxnc_value *value)
Set a parameter.
Definition SaxonCGlue.c:160
SAXONC_EXPORT int64_t getParameter(sxnc_parameter *parameters, int parLen, const char *name)
Get a parameter from the list.
Definition SaxonCGlue.c:136
SAXONC_EXPORT void setProperty(sxnc_property **properties, int *propLen, int *propCap, const char *name, const char *value)
Set a property.
Definition SaxonCGlue.c:186
SAXONC_EXPORT char * getProperty(sxnc_property *properties, int propLen, const char *name)
Get a property from the list.
Definition SaxonCGlue.c:148
EXTERN_SAXONC SAXONC_EXPORT const char * version(sxnc_environment *environi, sxnc_processor *proc)
Get the Saxon version.
Definition SaxonCProcessor.c:6
SAXONC_EXPORT sxnc_value * evaluate(sxnc_environment *environi, sxnc_xpath *proc, char *cwd, char *xpathStr, char *encoding, sxnc_parameter *parameters, sxnc_property *properties, int parLen, int propLen)
Compile and evaluate an XPath expression, supplied as a character string, with properties and paramet...
Definition SaxonCXPath.c:82
SAXONC_EXPORT sxnc_value * evaluateSingle(sxnc_environment *environi, sxnc_xpath *proc, char *cwd, char *xpathStr, char *encoding, sxnc_parameter *parameters, sxnc_property *properties, int parLen, int propLen)
Compile and evaluate an XPath expression for which the result is expected to be a single XdmItem or N...
Definition SaxonCXPath.c:128
SAXONC_EXPORT bool effectiveBooleanValue(sxnc_environment *environi, sxnc_xpath *proc, char *cwd, char *xpathStr, char *encoding, sxnc_parameter *parameters, sxnc_property *properties, int parLen, int propLen)
Evaluate an XPath expression, returning the effective boolean value of the result.
Definition SaxonCXPath.c:176
SaxonApiException.
Definition SaxonApiException.h:24
The SaxonProcessor class acts as a factory for generating XQuery, XPath, Schema and XSLT compilers.
Definition SaxonProcessor.h:117
An XPathProcessor represents a factory to compile, load and execute XPath expressions.
Definition XPathProcessor.h:64
UnprefixedElementMatchingPolicy convertEnumPolicy(int n)
Convert an int into an UnprefixedElementMatchingPolicy.
Definition XPathProcessor.h:283
void setBackwardsCompatible(bool option)
Say whether XPath 1.0 backwards compatibility mode is to be used.
SaxonProcessor * getSaxonProcessor()
Get the SaxonProcessor which created this XPathProcessor.
Definition XPathProcessor.h:386
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 setCaching(bool caching)
Say whether the compiler should maintain a cache of compiled expressions.
void importSchemaNamespace(const char *uri)
Import a schema namespace.
The class XdmItem represents an item in a sequence, as defined by the XDM data model.
Definition XdmItem.h:31
An XdmValue represents a value in the XDM data model.
Definition XdmValue.h:43