The functionality you need was added after the 3.1.0 release. Its in the
current code base in the CVS respository, and will be in the next release
of course. But, in the meantime, you'd have to get the most recent code and
build it yourself.
The deal is that the SAXParser will call out with a Locator object. You
don't own it, you can just store a pointer and use it for the life of the
parse event. From it you can query current line/col/id information.
If you override the setDocumentLocator() method, you will be called at the
start of the parse:
virtual void setDocumentLocator(const Locator* const locator) = 0;
The passed locator object pointer you just store away inside your handler.
You can then ask the locator about this info. Don't use use the locator
after the end of parse() and don't try to delete it.
----------------------------------------
Dean Roddey
Software Weenie
IBM Center for Java Technology - Silicon Valley
[EMAIL PROTECTED]
Monika Mevenkamp <[EMAIL PROTECTED]> on 04/17/2000 09:51:25 AM
Please respond to [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
cc:
Subject: semantic error reporting in SAXParser ?
Dr. Xerces:
I am trying to figure the best way out to handle semantic errors in
a SAXParser. I did not find how I get to the positioning information
(i.e. file,line,char position) from within a HandlerBase method
(in my case start/endElement);
In case you need a little more context, here is how I set my parser up:
----------------------------------------------------------------------------
Driver driver; // one of my own data structures
DriverXMLHandler handler(&driver); // DriverXMLHandler derives
// from SAXHandlerBase which in turn
// derives from HandlerBase
SAXParser parser;
parser.setDoValidation(true);
parser.setDocumentHandler(&handler);
parser.setErrorHandler(&handler);
try {
parser.parse(configurationFile);
}
catch (const SAXException& toCatch) {
ReportException("Error:", toCatch);
return 1;
}
catch (const XMLException& toCatch) {
String msg = String("Can't open '") + args.configurationFile + "'.";
ReportException(msg, toCatch);
return 1;
}
----------------------------------------------------------------------------
SAXHandlerBase implements error, fatalError, and warning.
DriverXMLHandler implements startElement and endElement.
it updates the Driver instance that it received upon construction
according to what is found in the file that is being parsed.
Whenever there is a semnatic error in the parsed file
DriverXMLHandler::start/endElement should report it in terms of
file and line number and go on.
----------------------------------------------------------------------------
I'd appreciate any help.
Monika
--
Mail: Computer Science Dept., MS 132 Office: 3054 Duncan Hall
Rice University Voice: (713) 348-5693
6100 South Main Street Fax: (713) 348-5136
Houston, TX 77005-1892 email: [EMAIL PROTECTED]
c