You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by meng-kim <me...@mediaring.com.sg> on 2002/04/30 10:21:29 UTC
exception using visual C++
I try to create a simple project to using the following code but encounter exception when the program exit.
#include <xercesc/util/PlatformUtils.hpp>
//#include <xercesc/sax/SAXException.hpp>
//#include <xercesc/sax/SAXParseException.hpp>
#include <xercesc/parsers/DOMParser.hpp>
//#include <xercesc/dom/DOM_DOMException.hpp>
//#include "DOMCount.hpp"
#include <string.h>
#include <stdlib.h>
//#include <fstream.h>
#include "iostream.h"
int main(int argc, char* argv[])
{
XMLPlatformUtils::Initialize();
const char* xmlFile = "e:\\temp\\LogConfiguration.xml";
// Instantiate the DOM parser.
DOMParser* parser = new DOMParser;
// And create our error handler and install it
//DOMCountErrorHandler errorHandler;
//parser->setErrorHandler(&errorHandler);
parser->parse(xmlFile);
DOM_Document doc = parser->getDocument();
//unsigned int elementCount = doc.getElementsByTagName("*").getLength();
// Print out the stats that we collected and time taken.
//cout << xmlFile << ": " << elementCount << " elems)." << endl;
//
// Delete the parser itself. Must be done prior to calling Terminate, below.
//
delete parser;
parser = NULL;
// And call the termination method
//crush, why?????
XMLPlatformUtils::Terminate();
return 0;
}
logConfiguration.xml
==========================================================
<?xml version="1.0" encoding="UTF-8"?>
<LogConfiguration>
<General>
<filename>1.txt</filename>
</General>
<CMRCallLog>
<PhoneNo>123</PhoneNo>
</CMRCallLog>
</LogConfiguration>
When the program terminates, it will encounter exception. However, removal of XMLPlatformUtils::Terminate() fix the problems.
Why?
Thanks
Re: exception using visual C++
Posted by Alberto Massari <al...@exln.com>.
At 16.21 30/04/2002 +0800, you wrote:
>I try to create a simple project to using the following code but encounter
>exception when the program exit.
>
>[...]
>int main(int argc, char* argv[])
>{
> XMLPlatformUtils::Initialize();
>
> const char* xmlFile = "e:\\temp\\LogConfiguration.xml";
>
> // Instantiate the DOM parser.
> DOMParser* parser = new DOMParser;
>
> parser->parse(xmlFile);
>
> DOM_Document doc = parser->getDocument();
> delete parser;
> parser = NULL;
>
> // And call the termination method
> //crush, why?????
> XMLPlatformUtils::Terminate();
After you call Terminate, you shouldn't do any work on Xerces data
structures; but you still have a DOM_Document object on the stack, whose
destructor will be called after the Terminate() call.
Try changing the code into
XMLPlatformUtils::Initialize();
{
DOMParser* parser=.....
...
DOM_Document doc= ....
...
}
XMLPlatformUtils::Terminate();
Alberto
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org