Sample 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.

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

SAXWriter, DOMWriter

 

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, while DOMWriter uses either the validating or non-validating DOM parser. DOMWriter also provides a feature to set the output Java encoding through the -e switch.

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 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.