[I wasn't the one asking in the first place, but..]
Excellent! I was looking for something like this, since even though I am
following this mailing list for quite some time now, there wasn't so
concise sample of code to use.

Thanks a lot,

Drazen

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] 
> Sent: Monday, July 07, 2003 12:03 PM
> To: [email protected]
> 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]
> 
> 
> 
> 
> 
> 

Reply via email to