Six samples are distributed with this installation under the
jwsdp.home/sjsxp/samplesdirectory:
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
XMLEventobject 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
StartElementandEndElementevents 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
XMLEventWriterAPIs.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 thesamplesdirectory 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.javasample, go to thesjsxp/samplesdirectory 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.jarJAR 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.jarproperty as shown:ant -Dstax.api.jar="<JSR 173 API LOCATION>" cursor.CursorParseIf Ant cannot find the
sjsxp.jarfile, override thesjsxp.jarproperty 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.javafor example:First, compile
CursorParse.javawith 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.xmlis bundled with the SJSXP distribution and is used by several of the samples.