Board index » cppbuilder » BCB and Xerces

BCB and Xerces


2004-08-06 11:52:59 PM
cppbuilder53
Hallo,
ich try to use the Xerces C++ XercesDOMParser Class, after compiling and
linking in my code it works, but using the parse Method leading to throwing
an exception from the class xerces_2_5::SAXParseException, here the code:
myClass::myClass()
{
setlocale(LC_ALL,NULL);
setlocale(LC_NUMERIC,"C");
try
{ XMLPlatformUtils::Initialize();
InitialisationSuccess=true;
}
catch (const XMLException& toCatch)
{ char* message=XMLString::transcode(toCatch.getMessage());
String ErrorMessage=message;
ShowMessage("Error during initialization! :\n" + ErrorMessage);
XMLString::release(&message);
InitialisationSuccess=false;
}
}
bool myClass::ParseIt()
{ if (InitialisationSuccess)
{ XercesDOMParser* parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Always);
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(errHandler);
try
{ parser->parse(xmlFile);
}
catch (const XMLException& toCatch)
{ char* message = XMLString::transcode(toCatch.getMessage());
String ErrorMessage=message;
ShowMessage("Error during XML! :\n" + ErrorMessage);
XMLString::release(&message);
delete parser;
delete errHandler;
return false;
}
catch (const DOMException& toCatch)
{ char* message = XMLString::transcode(toCatch.msg);
String ErrorMessage=message;
ShowMessage("Error during DOM! :\n" + ErrorMessage);
XMLString::release(&message);
delete parser;
delete errHandler;
return false;
}
catch (...)
{ ShowMessage("Unexpected Exception!");
delete parser;
delete errHandler;
return false;
}
delete parser;
delete errHandler;
return true;
}
else return false;
}
----------
In the line parser->parse(xmlFile); I get the exception. Anyone knows, where
is my mistake??
Thanks.
OLi
 
 

Re:BCB and Xerces

"Oliver Penz" < XXXX@XXXXX.COM >writes:
I haven't used Xerces, so here are just some wild guesses:
Quote
myClass::myClass()
{
setlocale(LC_ALL,NULL);
setlocale(LC_NUMERIC,"C");

try
{ XMLPlatformUtils::Initialize();
InitialisationSuccess=true;
}
catch (const XMLException& toCatch)
{ char* message=XMLString::transcode(toCatch.getMessage());
String ErrorMessage=message;
ShowMessage("Error during initialization! :\n" + ErrorMessage);
XMLString::release(&message);
InitialisationSuccess=false;
}
}
This InitialisationSuccess data member looks fishy. Why don't you just
let the exception escape from the constructor to signal the creator of
the object that the construction failed?
Quote
bool myClass::ParseIt()
{ if (InitialisationSuccess)
{ XercesDOMParser* parser = new XercesDOMParser();
Is there a reason why you create so many objects dynamically? Doing
XercesDOMParser parser;
etc. would be *much* simpler, if it's possible. If not, consider using
smart pointer objects instead of all these exception handlers with all these
deletes. Your code will be much simpler, which means that the chance of
doing something wrong will be much smaller. And you will only need one
exception handler that, maybe apart from logging, simply translates caught
exceptions into return false;.
Quote
parser->setValidationScheme(XercesDOMParser::Val_Always);
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
You seem to be lying to the compiler here. How is HandlerBase defined?
 

Re:BCB and Xerces

Hi,
Quote
I haven't used Xerces, so here are just some wild guesses:

This InitialisationSuccess data member looks fishy. Why don't you just
let the exception escape from the constructor to signal the creator of
the object that the construction failed?
Okay is a little bit dirty but fast and the constructor works.


>bool myClass::ParseIt()
>{ if (InitialisationSuccess)
>{ XercesDOMParser* parser = new XercesDOMParser();

Is there a reason why you create so many objects dynamically? Doing

XercesDOMParser parser;
I tried it, same result.
Quote
>parser->setValidationScheme(XercesDOMParser::Val_Always);
>ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();

You seem to be lying to the compiler here. How is HandlerBase defined?
This was the part of the original example code from Apache.org other
examples don't create this ErrorHandler so I tried it too and what should I
say: Same result.
But is a good idea to regard the HandlerBase.
OLi
 

{smallsort}

Re:BCB and Xerces

"Oliver Penz" < XXXX@XXXXX.COM >escreveu na mensagem
Quote
Hallo,

ich try to use the Xerces C++ XercesDOMParser Class, after compiling and
linking in my code it works, but using the parse Method leading to
throwing
an exception from the class xerces_2_5::SAXParseException, here the code:
Hi OLi,
Which BCB version are you using?
Saulo I. Regis
www.pictureprogressbar.com
Picture ProgressBar - Your Users Will Love It!