![]() |
XML SAX Sample Application |
XML SAX Sample Application
This document describes how to utilize the XML SAX sample application in conjunction with Sun ONE Application Server version 7.This sample application document contains the following sections:
Overview
The XML SAX sample application uses the SAXLocalNameCount program to count the number of unique element local names in an XML document, ignoring the namespace name for simplicity. This example also shows one way to turn on DTD validation and how to use a SAX ErrorHandler.There are several ways to parse a document using SAX and JAXP. The first step is to bootstrap a parser.
There are two ways to bootstrap a parser: one is to use only the SAX API, the other is to use the JAXP utility classes in the javax.xml.parsers package. The JAXP utility classes in the javax.xml.parsers package will be used in this example.
After bootstrapping a parser/XMLReader, there are several ways to begin a parse. In this example, the SAX API will be used.
Compiling and Assembling the Application
This section contains instructions to build and assemble the XML SAX sample application using a Command Line Interface (CLI).
Go to s1as_install_dir/samples/xml/sax/src
Clean the application project area (optional).
- Execute the command asant
- The default target core will be executed to compile the application.
- Execute the command asant clean to remove the sample application assemble and build directories.
Running the Sample Application
To run the sample application, do the following:
Go to s1as_install_dir/samples/xml/sax/src and execute the following command:
Alternatively, you may run both of the previous tests at the same time by doing the following:
Go to s1as_install_dir/samples/xml/sax/src and execute the following command:
- asant rundtd
- If your build was successful, the sample displays the following information:
- [java] Local Name "Order" occurs 1 times
- [java] Local Name "Quantity" occurs 5 times
- [java] Local Name "Tax" occurs 1 times
- [java] Local Name "Item" occurs 5 times
- [java] Local Name "Customer" occurs 1 times
- [java] Local Name "Receipt" occurs 1 times
- [java] Local Name "Name" occurs 1 times
- [java] Local Name "Subtotal" occurs 1 times
- [java] Local Name "Total" occurs 1 times
- [java] Local Name "Title" occurs 5 times
- [java] Local Name "ID" occurs 5 times
- [java] Local Name "Cardnum" occurs 1 times
- [java] Local Name "UnitPrice" occurs 5 times
- [java] Local Name "Manifest" occurs 1 times
- asant runnodtd
- The application should print the following results:
- [java] Local Name "name" occurs 1 times
- [java] Local Name "reservation" occurs 1 times
- [java] Local Name "seat" occurs 1 times
- [java] Local Name "examples" occurs 1 times
- [java] Local Name "book" occurs 1 times
- [java] Local Name "author" occurs 1 times
- [java] Local Name "a" occurs 1 times
- [java] Local Name "title" occurs 1 times
- [java] Local Name "section" occurs 1 times
- [java] Local Name "departure" occurs 1 times
- [java] Local Name "signing" occurs 1 times
Go to s1as_install_dir/samples/xml/sax/src and execute the following command:
- asant run
Generating Javadocs
To understand sample application source code better, you can refer to the related javadocs. To generate javadocs, run the command
After javadocs are generated, you can access them at
- asant javadocs
- or
- asant all
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.
Last Updated July 12, 2002