Sorry, if this has been answered previously.  I checked the archives and sample 
code and could not find the answer.

Is this the right pattern to execute a XPath Query on Xerces DOM?  This code 
used to work with the source in CVS repository that I downloaded couple of 
months back.  The official release causes an access violation on the following 
line

XalanElement*   rootElem = theWrapper.getDocumentElement();


I am using Xerces 2.2 and Xalan 1.5 on Windows platform.  Any help/suggestions 
would be really appreciated.  Also, we plan to use XPath expressions heavily 
(and call this method very often( so any pointers on better implementations to 
improve performance would be greatly appreciated.

Thanks,

Ravin


-------------------------------------------------------------------------------------
Declarations for objects used....

DOMDocument* xercesDocument;
std::wstring xPathQuery;
DOMNode* m_pDOMNode;
................
................
................
................

XercesDOMSupport theDOMSupport;
XercesDocumentWrapper theWrapper(xercesDocument, false, false);

// Initialize the XPath subsystem
static XPathInit theInit;

// configure the objects needed for XPath to work with the Xerces DOM
XPathEnvSupportDefault  theEnvSupport;
XObjectFactoryDefault   theXObjectFactory;
XPathExecutionContextDefault    theExecutionContext(theEnvSupport, 
theDOMSupport, theXObjectFactory);
XPathFactoryDefault     theXPathFactory;
XPathProcessorImpl      theXPathProcessor;
                
XalanElement*   rootElem = theWrapper.getDocumentElement();
XalanNode*      currentNode = theWrapper.mapNode(m_pDOMNode);
                
// first get the context nodeset
XPath* const contextXPath = theXPathFactory.create(); //will be deleted by 
theXPathFactory destructor
XPathConstructionContextDefault         theXPathConstructionContext;
theXPathProcessor.initXPath(*contextXPath, 
                            theXPathConstructionContext,
                                  XalanDOMString(strQuery.c_str()), 
                                  ElementPrefixResolverProxy(rootElem, 
theEnvSupport, theDOMSupport));
                
XObjectPtr      xObj = contextXPath->execute(currentNode,
                        ElementPrefixResolverProxy(rootElem, theEnvSupport, 
theDOMSupport),
                        theExecutionContext);
                
if( xObj->getType() != XObject::eTypeNodeSet )
{
        //No results returned...
}
else
{
        const NodeRefListBase&  nodeset = xObj->nodeset();
        //ok, now we get the matching xalan node, add to the vector
        size_t len = nodeset.getLength();
        for (size_t i=0; i<len; i++)
        {
                XalanNode* const        node = nodeset.item(i);
                        //Push the results in XercesNodeVector using 
Wrapper.mapNode(node) method.
        }
}

Reply via email to