Hi

I have a DOM_Document and want to use a DOM_Element in that document. I
which to apply an XPath expression to any selected node in the DOM_Document.
Tried to use the SimpleXPathAPI example but I get a XPathParserException.

What am I doing wrong?? *XPathExp contains //


MY CODE!!!!!!!!!!!!!!!!

bool MyClass::XpathSolve(char *XPathExp)
{
    XalanDOMString XPathEx(XPathExp);
        int             theResult = 0;
    try
                {
                        XMLPlatformUtils::Initialize();

                        XPathEvaluator::initialize();

                        {
                                // Initialize the XalanSourceTree subsystem...
                                XalanSourceTreeInit             
theSourceTreeInit;

                                // We'll use these to parse the XML file.
                                XalanSourceTreeDOMSupport               
theDOMSupport;
                                XalanSourceTreeParserLiaison    
theLiaison(theDOMSupport);

        //convert DOM to Xalan
        XercesDocumentBridge *XDocBridge = new
XercesDocumentBridge(m_LoadDOMDocument); //convert DOM_Document
        XercesBridgeNavigator *BridgeNav = new
XercesBridgeNavigator(XDocBridge);
        XercesElementBridge *XElemBridge = new
XercesElementBridge(m_LoadActiveNode ,*BridgeNav); //convert DOM_Element
        XalanElement* rootElem = XElemBridge;


                                // Hook the two together...
                                theDOMSupport.setParserLiaison(&theLiaison);

                                XPathEvaluator  theEvaluator;

                                // OK, let's find the context node...
                                XalanNode* const        theContextNode =
                                                theEvaluator.selectSingleNode(
                                                        theDOMSupport,
                                                        rootElem,
                                                        XPathEx.c_str(),0);

                                if (theContextNode == 0)
                                {
                                        cerr << "Warning -- No nodes matched 
the location path" << endl;
                                }
                                else
                                {
                                        // OK, let's evaluate the expression...
                                        const XObjectPtr        theResult(
                                                theEvaluator.evaluate(
                                                                theDOMSupport,
                                                                theContextNode,
                                                                XPathEx.c_str(),
                                                                0));

                                        assert(theResult.null() == false);

                                }
                        }

                        XPathEvaluator::terminate();

                        XMLPlatformUtils::Terminate();
                }
        catch(XPathParserException &e)
        {
            cerr << "XPATH-PARSER EXCEPTION" <<endl
                 << e.getMessage().c_str() << endl
                 << e.getType().c_str() <<endl
                 << e.getLineNumber() <<endl
                 << e.getColumnNumber() <<endl;
        }
        catch(const XPathException &e)
        {
            cerr << "XPATH EXCEPTION" <<endl
                 << e.getMessage().c_str() << endl
                 << e.getType().c_str() <<endl
                 << e.getLineNumber() <<endl
                 << e.getColumnNumber() <<endl;
        }
        catch(...)
                {
                        cerr << "Exception caught!" << endl;

                        theResult = -1;
                }

    return theResult;
}

regards

Troels Rossing
QualiWare
Phone +45 45 47 07 46

Reply via email to