Hi Sven,
Xerces tries to recover from non-fatal errors, so you should install a
DOMErrorHandler to get notified of any error, and return "false" to
abort parsing.
You can then check your error handler object for the number of errors
occurred, and their associated descriptions.
Alberto
Sven Bauhan wrote:
Hi,
to import an xml file I use a DOMBuilder (Xerces version 2.7). When I parse an
invalid XML file, I do not get an exception an the DOMDocument is also no
NULL pointer. But then the method getDocumentElement gives a NULL pointer. Is
this an error in the Xerces library?
This is my code:
-------------------
try {
this->parseXML( infile );
} catch ( XMLException& e ) {
d4err << "Xerces XML Exception: " << XercesString( e.getMessage() ) <<
endmsg;
throw XmlParseException( "XML parsing" );
} catch ( DOMException& e ) {
d4err << "Xerces DOM parser Exception: " << XercesString( e.getMessage() )
<< endmsg;
throw XmlParseException( "XML parsing" );
}
void ADSFile::parseXML( const helper::UnixPath& infile_ )
throw( XmlDbException, XMLException, DOMException ) {
XMLInit initXML;
XMLCh tmpStr[100];
XMLString::transcode( "LS", tmpStr, 99 );
DOMImplementationLS* impl =
DOMImplementationRegistry::getDOMImplementation( tmpStr );
DOMBuilder* parser =
dynamic_cast<DOMImplementationLS*>( impl )->createDOMBuilder( DOMImplementationLS::MODE_SYNCHRONOUS,
0 );
if (parser->canSetFeature(XMLUni::fgDOMValidation, true))
parser->setFeature(XMLUni::fgDOMValidation, true);
if (parser->canSetFeature(XMLUni::fgDOMNamespaces, true))
parser->setFeature(XMLUni::fgDOMNamespaces, true);
if (parser->canSetFeature(XMLUni::fgDOMDatatypeNormalization, true))
parser->setFeature(XMLUni::fgDOMDatatypeNormalization,
true);
DOMDocument* doc;
doc = parser->parseURI( infile_.to_s().c_str() );
if ( ! doc ) {
throw XmlParseException( "Parsing of XML file failed!" );
}
DOMElement* root = doc->getDocumentElement();
XercesString rootName( root->getNodeName() );
...
}
-----------------------
Here I get a segmentation violation. I thought that the parser would throw a
XMLException or a DOMException which I caught above. Or it would deliver a
NULL pointer for the DOMDocument at least.
Is this an error in the xerces library or have I done something wrong?
Thanks, Sven