Sample Parser Applications

 

XML4J comes packaged with sample applications that demonstrate features of the parser using the SAX and DOM APIs.  The code is written in tutorial style, to help you understand how to perform common tasks using these API's.

The sample parsers presented here are:

Note: Make sure that XML4J and a JDK are loaded on your computer before running any of the sample parsers.

XML4J Note: Running the sample applications require that you have already loaded the XML4J software on your computer.

Java Note: Running the SAX and DOM parsers require that your computer is setup with a JDK. If you do not already have a JDK already on your computer down load one from Sun's Java website: http://java.sun.com or from IBM's website http://www.ibm.com/developer/java/ where you can find an "Enhanced Windows JDK" that is optimized for the Windows platform. The sample applications described in the following pages support Java 1 - JDK 1.1.6. 1.1.7, 1.1.8 or Java 2 - JDK 1.2.2.

UNIX Note: Command lines in the pages linked below use the Windows path separator ';' (semicolon) and directory separator '\' (backslash)..
On UNIX, use the ':' (colon) character to separate the JAR files in the classpath, and replace Windows directory separator '\' (backslash) with '/' (forward slash)
.

SAXWriter, DOM Writer

 

SAXWriter and DOMWriter parse a file, and print it out in XML format. 
The command line option, -f, is used to print files  in "canonical" XML format, so that two XML documents can be compared. They also display any errors or warnings that occurred during the parse. 

SAXWriter uses either the validating or non-validating SAX parser.

DOMWriter uses either the validating or non-validating DOM parser. DOMWriter also provides a -e switch to set the output Java encoding.

SAXCount, DOMCount

 

SAXCount and DOMCount parse your input file, and output the total parse time, along with counts of elements, attributes, text characters, and ignorable whitespace characters. SAXCount and DOMCount also display any errors or warnings that occurred during the parse.

SAXCount uses either the validating or non-validating SAX parser.
DOMCount uses either the validating or non-validating DOM parser

TreeViewer

 

TreeViewer displays the input XML file in a graphical tree-style interface.  It will also highlight lines that have well-formedness or validation errors.

DOMFilter

 

DOMFilter shows you how to search for specific elements in your XML document.  It uses getElementsByTagName() to traverse the DOM tree, looking for elements or attributes that match your specification.