Home > Articles > Web Services > XML

When using SOAP, how do I implement a simple API for XML?

The Simple API for XML (SAX) is a low-level, event-driven or event-based system which operates in a fashion similar to a Graphical User Interface (GUI). For instance, when a start tag is encountered during parsing, an event can be triggered which executes your event handler or callback function to handle the event. One benefit of this method is that it requires much less memory and resources than the DOM does because SAX doesn't store the document in memory. This can be extremely useful when dealing with very large XML documents. Another advantage to using the SAX callback functionality is that you can implement your own data structures for internally storing the document. Therefore, you don't have to make a copy of the parser's tree structure into one of your own structure, as you would have done with the DOM.

In the following sample code fragments, you will see some of the available event handlers, using the Apache.org parser. The following is a slightly modified version of the examples provided with the Apache.org parser. Here, the SAXHandlers class in the class header file encapsulates the event handlers for both document and error events.

See code:

Using this class, the handler object is registered for both document events and error events: (see below)

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.