Hello,

I am having a problem with Xerces C++ 2.3.0 where I am getting back a DOMText node from DOMLocator::getErrorNode(), instead of a DOMElement that I was expecting. I need to store all of the DOMElement nodes that generate errors when parsing (using a DOMBuilder), so I can refer to them later in my application. I am setting up my own error handler, which catches all of the errors as I expected, but then when I call getErrorNode() from the DOMLocator object that I get from the DOMError object passed into handleError(), it always returns a DOMTEXT node instead of a DOMElement node.

To test this I created a small xml document that contained an invalid element. The error handler caught the error (error message: Unknown element 'MyInvalidElement'). So when I got the DOMLocator and then asked for the error node, I expected to get the DOMElement that represents MyInvalidElement. But I get a DOMText node.

Is this correct behavior when catching this type of error?

If so, is there a way to get from the DOMText node to the DOMElement?

Below is a sample piece of code showing how I get the DOMNode:


bool cDOMBuilderErrorHandler::handleError(const DOMError &rDomError)
    {
    mSawErrors = true;

    if (rDomError.getSeverity() == DOMError::DOM_SEVERITY_WARNING)
        {
        cerr << "\nWarning at file ";
        }
    else if (rDomError.getSeverity() == DOMError::DOM_SEVERITY_ERROR)
        {
        do
            {
            DOMLocator *pDOMLocator = rDomError.getLocation() ;
            if (pDOMLocator == NULL)
                break ;

            DOMNode *pDOMNode = pDOMLocator->getErrorNode() ;
            if (pDOMNode == NULL)
                break ;

            // Expected pDOMNode to be a DOMElement, but its a DOMText node.

            } while (0) ;
        }
    else
        {
        cerr << "\nFatal Error at file ";
        }

    return true;
    }


Thanks in advance for your help
Larry Rosenzweig
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to