From b79d758e8eb1b3288300fd2388fe5e8ff66a45bb Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Wed, 1 Apr 2020 03:14:26 +0200 Subject: [PATCH] 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" --- src/xpath.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/xpath.cpp b/src/xpath.cpp index 7612718..1001227 100644 --- a/src/xpath.cpp +++ b/src/xpath.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -58,7 +59,8 @@ namespace duck { xercesc::MemBufInputSource input_buf(reinterpret_cast(parXML.c_str()), parXML.size(), "n/a", false); BatchResults retval; try { - AutoDelete context(xqilla.createContext(XQilla::XQUERY3_UPDATE, &xconfig)); + AutoDelete context(xqilla.createContext(XQilla::XQUERY3, &xconfig)); + xconfig.populateStaticContext(context); Node::Ptr ptr = context->parseDocument(input_buf); context->setContextItem(ptr); //see http://xqilla.sourceforge.net/docs/simple-api/classStaticContext.html#adc869a84712459fa49db67fe837c9b01 @@ -66,10 +68,12 @@ namespace duck { context->setDefaultElementAndTypeNS(ns_wide); for (const auto& xpath : parQueries) { - AutoDeleteArray xpath_wide = xercesc::XMLString::transcode(xpath.c_str()); - AutoDelete query(xqilla.parse(xpath_wide, context, nullptr, XQilla::NO_ADOPT_CONTEXT)); - context->setContextPosition(1); - context->setContextSize(1); + AutoDelete query(nullptr); + { + AutoContextInfoReset resetter(context); + AutoDeleteArray xpath_wide = xercesc::XMLString::transcode(xpath.c_str()); + query.set(xqilla.parse(xpath_wide, context, nullptr, XQilla::NO_ADOPT_CONTEXT)); + } Result result = query->execute(context); Item::Ptr item;