Hi,
this issue seems to reappear from time to time and maybe the
approach I'm taking can be of help here too. It's the answer to
a post some time ago on a slightly different yet connected problem.
I suggest you dig it up from the mailing archive (see Subject: below).
We successfully use a similar solution along with various Xerces/Xalan
distributions.
Good luck
Joerg
Previous post follows below:
Subject: Antwort: Can I change the nodeset that is returned by Xalan XPath?
Hi,
having received competent help from the community,
maybe I can be of help too.
We have the same scenario and use Xalan-C mainly for its XPath
capabilities.
We do something like this:
void select(xercesc::DOMNode * &node,
const std::string &xpath, // XPath expression evaluating to
a node set
xercesc::DOMDocument &document) {
XercesDOMSupport dom_support;
XercesParserLiaison parser_liaison;
XalanDocument *xalan_document = parser_liaison.createDocument
(&document, false, true);
XalanNode * root_context_node = xalan_document;
XalanElement *namespace_node = xalan_document->getDocumentElement();
const XalanDOMString expression(xpath.c_str());
DOMNode *target= 0;
XPathEvaluator evaluator;
const XalanNode* found = evaluator.selectSingleNode(
dom_support,
root_context_node,
expression.c_str(),
namespace_node);
if (found) {
XercesDocumentWrapper *xerces_document_wrapper =
parser_liaison.mapDocumentToWrapper(xalan_document);
DOMNode const *const_target =
xerces_document_wrapper->mapNode(node);
target = const_cast<DOMNode *>(const_target);
}
node = target;
}
Now your calling code can do with the passed DOMNode pointer what
it wants, maybe modify it.
Just observe the remark from David Bertoni if you keep your
XercesParserLiaison
and XercesDocumentWrapper outside the function performing the
selectSingleNode-call:
> If you're going to use XercesDocumentWrapper, make sure you always
re-build
> the wrapper after you've made modifications to the document, and make
sure
> you pass true for the buildWrapper parameter.
By the way, this works also for XPathEvaluator::selectNodeList()
to get a complete node set and for XPathEvaluator::evaluate() if
you're interested in non-node set XPath types such as string, number
and boolean.
Hope this helps.
Bye
Joerg
[EMAIL PROTECTED]