ILOG JRules User Guide > Integrating Application Data > Tasks > Using the XML Binding API > Configuring XML Binding > Handling XML Binding Error and Warning Messages

There are three types of error in the XML specification: error, fatal error and warning.

The package ilog.rules.xml defines the error classes and exceptions returned by an XML file parser:

In general, you pass a schema, an XML document, and a handler object to the XML driver, which processes the XML and invokes the appropriate methods.

images/apis.png

A user handler that is linked to a Simple API for XML (SAX) parser is notified of any SAX event during the parsing of a schema or an XML document. SAX is the protocol that most servlets and network-oriented programs use to transmit and receive XML documents because it is the fastest and least memory-intensive mechanism that is currently available for dealing with XML documents.

Rather than building a complete representation of the XML document, the SAX parser fires off a series of events as it reads the document from beginning to end. These events are passed to the event handler, which provides access to the contents of the document.

images/xmlsaxparser.png

To implement and declare an XML error handler:

  1. Use the ilog.rules.xml.util.IlrXmlErrorHandler interface enables you to filter or declare new errors during XML parsing.
  2. Implement the IlrXmlErrorHandler interface and declare it to an XML driver during its initialization to activate the XML binding error handling process.
  3. Errors and warnings are sent to this handler using processWarning or processError calls.
  4. Declare and memorize notified errors and warnings by calling the IlrXmlErrorManager methods.
  5. images/xmlerrors.png
  6. Implement a simple user error handler, using following code:
Public class MyXmlErrorHandler
Implements IlrXmlErrorHandler
{    
    IlrXmlErrorManager manager = null;
    void processWarning ( IlrXmlError error ) throws IlrXmlFatalErrorException
    {       
       manager.insertError ( error, this );
    }    
    void processError ( IlrXmlError error ) throws IlrXmlFatalErrorException 
    {       
       manager.insertError ( error, this );    
    }    
    ...
    void setErrorManager ( IlrXmlErrorManager manager )    
    {       
       this.manager = manager;    
    }
}
The handler transforms any XML warning into an error.
  1. To build a new XML driver with the previous error handler, use the following code:
// configuration setting
IlrResources resource = new IlrResources();
resource.put( "ilog.rules.xml.errorHandlerClass", "MyXmlErrorHandler" );
...
IlrXmlHelper.createDataDriver(resource);

Related Concepts

XML Binding
Web Service Binding

Related Tasks

Configuring the XML Parser

Related Samples and Tutorials

How to Run Rules Against XML Objects