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 "Lang, Jeff" <jl...@CSA.com> on 2002/01/18 21:46:00 UTC
Core Dump after instantiating a DOM_Node
I am running Xerces C++ 1.6.0 on Solaris. I compiled with g++.
I am trying to get my own programs to compile, but when I try parsing a
file, and then putting it into a DOM_Node I get an error when the
destructor is called on that DOM_Node.
for example:
#include <iostream>
#include <string>
#include <util/PlatformUtils.hpp>
#include <framework/StdInInputSource.hpp>
#include <parsers/DOMParser.hpp>
#include <dom/DOM_DOMException.hpp>
#include <framework/MemBufInputSource.hpp>
#include <util/XMLString.hpp>
#include <dom/DOM_Node.hpp>
int main(int argc, char* argv[]){
try{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch){
cerr << "Error during initialization! :\n"
<< XMLString::transcode(toCatch.getMessage()) << endl;
return 1;
}
// Instantiate the DOM parser.
DOMParser * parser = new DOMParser;
char *XMLcode="<testdata>this is only a test</testdata>";
StdInInputSource source;
try{
parser->parse(source);
}
catch (const XMLException& toCatch){
cerr << "\nError during parsing\n"
<< "Exception message is: \n"
<< XMLString::transcode(toCatch.getMessage()) << "\n" << endl;
return 1;
}
catch (const DOM_DOMException& toCatch){
cerr << "\nDOM Error during parsing\n"
<< "DOMException code is: \n"
<< toCatch.code << "\n" << endl;
return 1;
}
catch (...){
cerr << "\nUnexpected exception during parsing\n";
return 1;
}
DOM_Node doc = parser->getDocument();
//clean up
delete parser;
XMLPlatformUtils::Terminate();
cout<<"Core Dump comes after this point"<<endl;
return 0;
}
If i were to comment out the line instanciating the DOM_Node this will
run without any problems.
Any ideas what it might be?
Thanks in advance,
Jeff Lang
Re: Core Dump after instantiating a DOM_Node
Posted by Tinny Ng <tn...@ca.ibm.com>.
The DOM_Node destructor is called at the end of main AFTER
XMLPlatformUtils::Terminate(). This is similar to the problem
described in FAQ http://xml.apache.org/xerces-c/faq-parse.html#faq-29.
It is not valid to have DOM_Node destructor being called after the
Xerces-C++ system is terminated. Try nesting your DOM_Node
instantiation inside an inner loop.
Tinny
"Lang, Jeff" wrote:
> I am running Xerces C++ 1.6.0 on Solaris. I compiled with g++.I am
> trying to get my own programs to compile, but when I try parsing a
> file, and then putting it into a DOM_Node I get an error when the
> destructor is called on that DOM_Node.for example:#include <iostream>
> #include <string>
> #include <util/PlatformUtils.hpp>
> #include <framework/StdInInputSource.hpp>
> #include <parsers/DOMParser.hpp>
> #include <dom/DOM_DOMException.hpp>
> #include <framework/MemBufInputSource.hpp>
> #include <util/XMLString.hpp>
> #include <dom/DOM_Node.hpp>
>
> int main(int argc, char* argv[]){
> try{
> XMLPlatformUtils::Initialize();
> }
> catch (const XMLException& toCatch){
> cerr << "Error during initialization! :\n"
> << XMLString::transcode(toCatch.getMessage()) << endl;
> return 1;
> }
>
> // Instantiate the DOM parser.
> DOMParser * parser = new DOMParser;
>
> char *XMLcode="<testdata>this is only a test</testdata>";
> StdInInputSource source;
>
> try{
> parser->parse(source);
> }
> catch (const XMLException& toCatch){
> cerr << "\nError during parsing\n"
> << "Exception message is: \n"
> << XMLString::transcode(toCatch.getMessage()) << "\n" <<
> endl;
> return 1;
> }
> catch (const DOM_DOMException& toCatch){
> cerr << "\nDOM Error during parsing\n"
> << "DOMException code is: \n"
> << toCatch.code << "\n" << endl;
> return 1;
> }
> catch (...){
> cerr << "\nUnexpected exception during parsing\n";
> return 1; }
>
> DOM_Node doc = parser->getDocument();
>
> //clean up
> delete parser;
>
> XMLPlatformUtils::Terminate();
> cout<<"Core Dump comes after this point"<<endl;
> return 0;
> } If i were to comment out the line instanciating the DOM_Node this
> will run without any problems.Any ideas what it might be?Thanks in
> advance,Jeff Lang