I am using the Xerces C ++ DOM parser to read some XML files in a Visual C ++ project. I have a class with a method parse()that needs to read and validate the source XML file. This is what the method looks like:
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/framework/LocalFileInputSource.hpp>
using namespace std;
XERCES_CPP_NAMESPACE_USE
unsigned long RulesParser::parse( const wstring &xmlFile )
{
if( parserInitialized_ == false ) {
try {
XMLPlatformUtils::Initialize();
} catch( XMLException const &e ) {
return Status::PARSER_INIT_FAIL;
}
}
parserInitialized_ = true;
if( pDOMParser_ != NULL ) {
delete pDOMParser_;
}
pDOMParser_ = new XercesDOMParser;
pDOMParser_->setDoNamespaces( true );
pDOMParser_->setDoSchema( true );
pDOMParser_->setValidationScheme( XercesDOMParser::Val_Always );
pDOMParser_->setValidationSchemaFullChecking( true );
auto_ptr< LocalFileInputSource > srcFile;
try {
srcFile.reset( new LocalFileInputSource( xmlFile.c_str() ) );
} catch( const XMLException &e ) {
return Status::XML_SOURCE_LOAD_ERROR;
}
try {
pDOMParser_->parse( *srcFile );
} catch( const XMLException &e ) {
return Status::XML_SOURCE_PARSE_ERROR;
} catch( const DOMException &e ) {
return Status::XML_SOURCE_PARSE_DOM_ERROR;
}
return Status::OK;
}
The documentation for LocalFileInputSourcesays that the constructor will throw XMLExceptionif the path is not allowed for the file. However, I can call this method with any arbitrary string, and it runs to the end without any exceptions. What am I doing wrong?
, XercesDOMParser::parse() , SAXException - , . , , , DOM SAX - , DOM- SAX?