Sun Java Streaming XML Parser Sample Applications

Implementation Version: 1.0.1

Samples:

Six samples are distributed with this installation under the jwsdp.home/sjsxp/samples directory:

cursor/CursorParse.java
This sample shows how to use the StAX Cursor (XMLStreamReader) APIs to parse an XML file.
cursor2event/CursorApproachEventObject.java
This sample shows how an application can get information as an XMLEvent object when using the cursor approach.
event/EventParse.java
This sample shows how to use the StAX Event (XMLEventReader) APIs to parse an XML file.
filter/MyStreamFilter.java
This sample shows how to use the StAX Stream Filter APIs. This filter accepts only the StartElement and EndElement events and filters out all other events.
readnwrite/EventProducerConsumer.java
This sample shows how the StAX producer/consumer mechanism can be used to read and write simultaneously. This sample also shows that a stream can be modified or new events can be added dynamically and then written to a different stream using the XMLEventWriter APIs.
writer/CursorWriter.java
This sample shows how to use the StAX Writing APIs to write an XML file programmatically.

Running the Samples Using Ant

Use the Ant build file (build.xml) in the samples directory to run the SJSXP samples. The Ant target you execute to run the sample is directory name and . (dot) and sample's file name. For example, to run the CursorParse.java sample, go to the sjsxp/samples directory and type the following on the command line:

ant cursor.CursorParse

If the StAX (JSR 173) APIs JAR file name is not jsr173_1.0_api.jar, or is not at the same location as the sjsxp.jar JAR file, you will get an error when you run the samples. If this occurs, you should tell Ant the location of the StAX APIs by overriding the stax.api.jar property as shown:

ant -Dstax.api.jar="<JSR 173 API LOCATION>" cursor.CursorParse

If Ant cannot find the sjsxp.jar file, override the sjsxp.jar property as shown:

ant -Dsjsxp.jar="sjsxp.jar location" cursor.CursorParse

Running the Samples Manually

You can also run the samples manually. To do so, go to the samples directory and change to the directory that contains the sample you want to run. To run CursorParse.java for example:

First, compile CursorParse.java with following command:

javac -classpath ../jsr173_1.0_api.jar CursorParse.java

Then, run the sample by issuing the following command:

java -classpath .:../sjsxp.jar:../jsr173_api.jar  cursor.CursorParse -x 1 ./samples/data/BookCatalogue.xml

BookCatalogue.xml is bundled with the SJSXP distribution and is used by several of the samples.