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
andEndElement
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.
Use the Ant build file (
build.xml
) in thesamples
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 theCursorParse.java
sample, go to thesjsxp/samples
directory and type the following on the command line:ant cursor.CursorParseIf the StAX (JSR 173) APIs JAR file name is not
jsr173_1.0_api.jar
, or is not at the same location as thesjsxp.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 thestax.api.jar
property as shown:ant -Dstax.api.jar="<JSR 173 API LOCATION>" cursor.CursorParseIf Ant cannot find the
sjsxp.jar
file, override thesjsxp.jar
property as shown:ant -Dsjsxp.jar="sjsxp.jar location" cursor.CursorParse
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.javaThen, 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.