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 Jason Jesso <jj...@global-matrix.com> on 2001/11/30 18:34:48 UTC
xml4c parsing problem
I am new to using xml4C and am trying to write a simple example in C++.
I am using xml4c from IBM for AIX4.3.3.
I have no problem with an xml file with no error's, but only a problem
with something like:
<HELLO>
fnkjsdsf
<HELLO>
I get the following error when I run my program:
IOT/Abort trap(coredump)
Can anybody help??
My program is:
#include <iostream.h>
#include "dom/DOM.hpp"
#include "parsers/IDOMParser.hpp"
#include "util/PlatformUtils.hpp"
#include "idom/IDOM_DOMException.hpp"
#include "sax/ErrorHandler.hpp"
#include "sax/HandlerBase.hpp"
int
main( int ac, char* av[] )
{
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
cout << "Error during initialization! :\n"
<< toCatch.getMessage() << "\n";
return 1;
}
char* xmlFile = "x1.xml";
IDOMParser* parser = new IDOMParser();
parser->setValidationScheme(IDOMParser::Val_Always); // optional.
parser->setDoNamespaces(true); // optional
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(errHandler);
try {
parser->parse(xmlFile);
}
catch (const XMLException& toCatch) {
cout << "\nFile not found: '" << xmlFile << "'\n"
<< "Exception message is: \n"
<< toCatch.getMessage() << "\n" ;
return -1;
}
catch (const IDOM_DOMException& e)
{
cerr << "An IDOM error occured during parsing\n IDOMException
code: " << e.code << endl;
}
return 0;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: xml4c parsing problem
Posted by Jason Jesso <jj...@global-matrix.com>.
Hmmm, I got the example from:
http://xml.apache.org/xerces-c/program.html#ConstructIDOMParser
Maybe they should fix it.
Thanks for your help,
Jason
Tinny Ng wrote:
> Jason,
>
> You used HandlerBase as your error handler. And HandlerBase rethrow a
> SAXParserException with fatal error:
>
> inline void HandlerBase::fatalError(const SAXParseException& exception)
> {
> throw exception;
> }
>
> Since your program does not catch this exception, the program core dump.
>
> Add the following catch statement to your program will work:
>
> catch (const SAXParseException& e)
> {
> cerr << "An IDOM error occured during parsing, got SAXParseExpcetion
> " << endl;
> }
>
> Tinny
>
> Jason Jesso wrote:
>
> > I am new to using xml4C and am trying to write a simple example in C++.
> > I am using xml4c from IBM for AIX4.3.3.
> >
> > I have no problem with an xml file with no error's, but only a problem
> > with something like:
> >
> > <HELLO>
> > fnkjsdsf
> > <HELLO>
> >
> > I get the following error when I run my program:
> >
> > IOT/Abort trap(coredump)
> >
> > Can anybody help??
> >
> > My program is:
> >
> > #include <iostream.h>
> > #include "dom/DOM.hpp"
> > #include "parsers/IDOMParser.hpp"
> > #include "util/PlatformUtils.hpp"
> > #include "idom/IDOM_DOMException.hpp"
> > #include "sax/ErrorHandler.hpp"
> > #include "sax/HandlerBase.hpp"
> >
> > int
> > main( int ac, char* av[] )
> > {
> > try {
> > XMLPlatformUtils::Initialize();
> > }
> > catch (const XMLException& toCatch) {
> > cout << "Error during initialization! :\n"
> > << toCatch.getMessage() << "\n";
> > return 1;
> > }
> >
> > char* xmlFile = "x1.xml";
> > IDOMParser* parser = new IDOMParser();
> > parser->setValidationScheme(IDOMParser::Val_Always); // optional.
> > parser->setDoNamespaces(true); // optional
> >
> > ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
> > parser->setErrorHandler(errHandler);
> >
> > try {
> > parser->parse(xmlFile);
> > }
> > catch (const XMLException& toCatch) {
> > cout << "\nFile not found: '" << xmlFile << "'\n"
> > << "Exception message is: \n"
> > << toCatch.getMessage() << "\n" ;
> > return -1;
> > }
> > catch (const IDOM_DOMException& e)
> > {
> > cerr << "An IDOM error occured during parsing\n IDOMException
> > code: " << e.code << endl;
> > }
> >
> > return 0;
> >
> > }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: xml4c parsing problem
Posted by Tinny Ng <tn...@ca.ibm.com>.
Jason,
You used HandlerBase as your error handler. And HandlerBase rethrow a
SAXParserException with fatal error:
inline void HandlerBase::fatalError(const SAXParseException& exception)
{
throw exception;
}
Since your program does not catch this exception, the program core dump.
Add the following catch statement to your program will work:
catch (const SAXParseException& e)
{
cerr << "An IDOM error occured during parsing, got SAXParseExpcetion
" << endl;
}
Tinny
Jason Jesso wrote:
> I am new to using xml4C and am trying to write a simple example in C++.
> I am using xml4c from IBM for AIX4.3.3.
>
> I have no problem with an xml file with no error's, but only a problem
> with something like:
>
> <HELLO>
> fnkjsdsf
> <HELLO>
>
> I get the following error when I run my program:
>
> IOT/Abort trap(coredump)
>
> Can anybody help??
>
> My program is:
>
> #include <iostream.h>
> #include "dom/DOM.hpp"
> #include "parsers/IDOMParser.hpp"
> #include "util/PlatformUtils.hpp"
> #include "idom/IDOM_DOMException.hpp"
> #include "sax/ErrorHandler.hpp"
> #include "sax/HandlerBase.hpp"
>
> int
> main( int ac, char* av[] )
> {
> try {
> XMLPlatformUtils::Initialize();
> }
> catch (const XMLException& toCatch) {
> cout << "Error during initialization! :\n"
> << toCatch.getMessage() << "\n";
> return 1;
> }
>
> char* xmlFile = "x1.xml";
> IDOMParser* parser = new IDOMParser();
> parser->setValidationScheme(IDOMParser::Val_Always); // optional.
> parser->setDoNamespaces(true); // optional
>
> ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
> parser->setErrorHandler(errHandler);
>
> try {
> parser->parse(xmlFile);
> }
> catch (const XMLException& toCatch) {
> cout << "\nFile not found: '" << xmlFile << "'\n"
> << "Exception message is: \n"
> << toCatch.getMessage() << "\n" ;
> return -1;
> }
> catch (const IDOM_DOMException& e)
> {
> cerr << "An IDOM error occured during parsing\n IDOMException
> code: " << e.code << endl;
> }
>
> return 0;
>
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org