Fix error when running multiple xpaths or something like that.

This fixes the xqilla exception being thrown:
"It is an error for the context item to be undefined when using it"
This commit is contained in:
King_DuckZ 2020-04-01 03:14:26 +02:00
parent b536026f58
commit b79d758e8e

View file

@ -21,6 +21,7 @@
#include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLString.hpp>
#include <xqilla/exceptions/XQException.hpp> #include <xqilla/exceptions/XQException.hpp>
#include <xqilla/exceptions/XMLParseException.hpp> #include <xqilla/exceptions/XMLParseException.hpp>
#include <xqilla/context/ContextHelpers.hpp>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
@ -58,7 +59,8 @@ namespace duck {
xercesc::MemBufInputSource input_buf(reinterpret_cast<const XMLByte*>(parXML.c_str()), parXML.size(), "n/a", false); xercesc::MemBufInputSource input_buf(reinterpret_cast<const XMLByte*>(parXML.c_str()), parXML.size(), "n/a", false);
BatchResults retval; BatchResults retval;
try { try {
AutoDelete<DynamicContext> context(xqilla.createContext(XQilla::XQUERY3_UPDATE, &xconfig)); AutoDelete<DynamicContext> context(xqilla.createContext(XQilla::XQUERY3, &xconfig));
xconfig.populateStaticContext(context);
Node::Ptr ptr = context->parseDocument(input_buf); Node::Ptr ptr = context->parseDocument(input_buf);
context->setContextItem(ptr); context->setContextItem(ptr);
//see http://xqilla.sourceforge.net/docs/simple-api/classStaticContext.html#adc869a84712459fa49db67fe837c9b01 //see http://xqilla.sourceforge.net/docs/simple-api/classStaticContext.html#adc869a84712459fa49db67fe837c9b01
@ -66,10 +68,12 @@ namespace duck {
context->setDefaultElementAndTypeNS(ns_wide); context->setDefaultElementAndTypeNS(ns_wide);
for (const auto& xpath : parQueries) { for (const auto& xpath : parQueries) {
AutoDelete<XQQuery> query(nullptr);
{
AutoContextInfoReset resetter(context);
AutoDeleteArray<XMLCh> xpath_wide = xercesc::XMLString::transcode(xpath.c_str()); AutoDeleteArray<XMLCh> xpath_wide = xercesc::XMLString::transcode(xpath.c_str());
AutoDelete<XQQuery> query(xqilla.parse(xpath_wide, context, nullptr, XQilla::NO_ADOPT_CONTEXT)); query.set(xqilla.parse(xpath_wide, context, nullptr, XQilla::NO_ADOPT_CONTEXT));
context->setContextPosition(1); }
context->setContextSize(1);
Result result = query->execute(context); Result result = query->execute(context);
Item::Ptr item; Item::Ptr item;