Original Post
I am trying to learn Xerces to use XML files, I figured the first thing I should learn is to open XML files and extract their information so I went to the Xerces programming guide and tried to recreate a sample that should open an XML file. The program compiles but crashes when run, the Debug error is: Unhandled exception at 0x7c812afb in XML_test.exe: Microsoft C++ exception: xercesc_3_0::SAXParseException at memory location 0x0012f2f8.. This debug output is (obviously) only created when I remove the error handling around the " parser->parse(xmlFile); " command. This is the code I compiled: (copy pasted from this website], and a library include added): Am I missing something, do I have to include any more libs/header files? and now that I'm posting anyways, I'd like to ask what you think of Xerces and if you would recommend another XML package? Thanks A_B
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/sax/HandlerBase.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#pragma comment(lib, "xerces-c_3.lib") // I added this myself
#include <iostream>
using namespace std;
using namespace xercesc;
int main (int argc, char* args[]) {
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Error during initialization! :\n"
<< message << "\n";
XMLString::release(&message);
return 1;
}
XercesDOMParser* parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoNamespaces(true); // optional
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(errHandler);
char* xmlFile = "x1.xml";
try {
parser->parse(xmlFile); //<-- here is the problem
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return -1;
}
catch (const DOMException& toCatch) {
char* message = XMLString::transcode(toCatch.msg);
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return -1;
}
catch (...) {
cout << "Unexpected Exception \n" ;
return -1;
}
delete parser;
delete errHandler;
return 0;
}