Chapter 2 Sample Programs

Directory Contents

This directory contains the following files. See the book text on how to run these sample programs.

File Name Listing Number Description
readme.html NA This file
department.xml NA Sample XML document
department2.xml NA Invalid XML document
department.dtd NA DTD for department.xml
SimpleParse.java 2.1 Read and parse an XML document
SimpleParseAndPrint.java 2.2 Reproduce an XML document from a parsed structure
keyval.xml NA Sample XML document
MakeEltTblDOM.java 2.3 Extract key-value pairs and stores them into a hash table (DOM-based implementation)
NotifyStr.java 2.4 Trace methods of SAX DocumentHandler
MakeEltTblSAX.java 2.5 Extract Key-Value pairs and stores them into a hashtable (SAX-based implementation)
SimpleFilter.java 2.6 Modify structure of an XML document
SimpleFilter2.java 2.7 Modify structure of an XML document (inner class version)
MakeEltTblEltHandler.java 2.8 Extract key-value pairs and store them into HashTable (ElementHandler-based implementation)

How to run

Make sure CLASSPATH contains xml4j_1_n_n.jar.

SimpleParse (Listing 2.1)
Read and parse an XML document
R:\samples\chap2>java SimpleParse department.xml
SimpleParse (Listing 2.1)
Read and parse an illegal XML document
R:\samples\chap2>java SimpleParse department2.xml
       
SimpleParseAndPrint (Listing 2.2)
Reproduce an XML document from a parsed structure
R:\samples\chap2>java SimpleParseAndPrint department.xml
       
MakeEltTblDOM (Listing 2.3)
Extract key-value pairs and stores them into a hash table with DOM API
R:\samples\chap2>java MakeEltTblDOM keyval.xml
       
NotifyStr (Listing 2.4)
Trace methods of DocumentHandler
R:\samples\chap2>java NotifyStr com.ibm.xml.parser.SAXDriver deparment.xml
     
MakeEltTblSAX (Listing 2.5)
Extract Key-Value pairs and stores them into a hashtable with SAX API
R:\samples\chap2>java MakeEltTblSAX com.ibm.xml.parser.SAXDriver keyval.xml
     
SimpleFilter (Listing 2.6)
Modify structure of an XML document
R:\samples\chap2>java SimpleFilter department.xml
     
SimpleFilter2 (Listing 2.7)
Modify structure of an XML document (inner class)
R:\samples\chap2>java SimpleFilter department.xml
     
MakeEltTblEltHandler (Listing 2.8)
Extract key-value pairs and store them into HashTable with ElementHandler
R:\samples\chap2>java MakeEltTblEltHandler keyval.xml
     

Last modified: Thu Jan 28 18:16:28 JST 1999