Ms. Mevenkamp, first of all notice that we have split the
discussion group into two groups. To post questions about
Xerces Java you may want to post to [email protected]

You may want to take a look at the SAXWriter ( or SAX2Write if you want to know how to implement this under SAX2) sample under the
xml-xerces/java/samples/sax directory for an example of how to
report file/line information in your error handling.


The code that you need is something like this ( from the SAXWriter
sample):

/** Warning. */
   public void warning(SAXParseException ex) {
       System.err.println("[Warning] "+
                          getLocationString(ex)+": "+
                          ex.getMessage());
   }

   /** Error. */
   public void error(SAXParseException ex) {
       System.err.println("[Error] "+
                          getLocationString(ex)+": "+
                          ex.getMessage());
   }

   /** Fatal error. */
   public void fatalError(SAXParseException ex) throws SAXException {
       System.err.println("[Fatal Error] "+
                          getLocationString(ex)+": "+
                          ex.getMessage());
       throw ex;
   }

   /** Returns a string of the location. */
   private String getLocationString(SAXParseException ex) {
       StringBuffer str = new StringBuffer();

       String systemId = ex.getSystemId();
       if (systemId != null) {
           int index = systemId.lastIndexOf('/');
           if (index != -1)
               systemId = systemId.substring(index + 1);
           str.append(systemId);
       }
       str.append(':');
       str.append(ex.getLineNumber());
       str.append(':');
       str.append(ex.getColumnNumber());

       return str.toString();

   } // getLocationString(SAXParseException):String



Hope this helps,


From: Monika Mevenkamp <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: semantic error reporting in SAXParser ?
Date: Mon, 17 Apr 2000 11:51:25 -0500 (CDT)

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

______________________________________________________ Get Your Private, Free Email at http://www.hotmail.com



Reply via email to