Browse Prior Art Database

Simplify the XML document handler programs of XML SAX parser Disclosure Number: IPCOM000020029D
Original Publication Date: 2003-Oct-20
Included in the Prior Art Database: 2003-Oct-20
Document File: 3 page(s) / 89K

Publishing Venue



This paper discloses a design technique aimed to improve the modularity, readability and maintainability of XML SAX parser programs in Java; in particular, it addresses the structure of the SAX document handler programs when parsing an XML file. A modularized design is proposed in order to simplify the programming task. The related technical details are presented which exploit the Java Reflection API, and some refinements to the technique are also presented in order to improve its flexibility.

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 53% of the total text.

Page 1 of 3

Simplify the XML document handler programs of XML SAX parser

XML SAX parser requires that the software developer writes a document handler program which listens to the events fired by the parser for each XML element. Most of the work, when dealing with the SAX interface, is to create the document handler. In Java, the document handler class must contain the following methods: startElement, endElement, characters Switches and logic must be inserted in these methods in order to distinguish among the different XML elements and perform the corresponding actions. The size and complexity of the document handler class increases with the number of XML tags up to reaching a level where readability and maintenance become very difficult. In this article, it is proposed the possibility to isolate in a separate class all the code relative to each XML tag. In this way, whenever a new tag is added or changed, the document handler program itself does not need to be changed, but only a small external class is added or changed.

    As a first step of the disclosed design technique, a generalized document handler must be written that, whenever a tag is encountered in the XML file parsing, invokes a specific class for the corresponding XML element. This "element class" can be an external file that implements all the needed methods (startElement, endElement, characters). To achieve this dynamic calling of external classes by the SAX parser, it is proposed to use the Java Reflection feature, namely the class.forName and classToRun.newInstance methods.

    The following is the code for a general startElement method. The other...