background image

Building and Running the Filter Example

<< Filtering the Stream | Creating an Event Producer Consumer >>
<< Filtering the Stream | Creating an Event Producer Consumer >>

Building and Running the Filter Example

Building and Running the Filter Example Using NetBeans IDE
Follow these instructions to build and run the Filter example on your Application Server
instance using the NetBeans IDE.
1. In NetBeans IDE, select File
Open Project.
2. In the Open Project dialog, navigate to the tut-install/javaeetutorial5/examples/stax/
directory.
3. Select the filter folder.
4. Select the Open as Main Project check box.
5. Click Open Project Folder.
6. In the Projects tab, right-click the filter project and select Properties. The Project
Properties dialog is displayed.
7. Enter the following in the Arguments field:
-f BookCatalog.xml
8. Click OK.
9. Right-click the filter project and select Run Project.
Building and Running the Filter Example Using Ant
To compile and run the Filter example using Ant, in a terminal window, go to the
tut-install/javaeetutorial5/examples/stax/filter/ directory and type the following:
ant run-filter
Read-and-Write Example
Located in the tut-install/javaeetutorial5/examples/stax/readnwrite/ directory,
EventProducerConsumer.java
demonstrates how to use a StAX parser simultaneously as both
a producer and a consumer.
The StAX XMLEventWriter API extends from the XMLEventConsumer interface, and is referred
to as an event consumer. By contrast, XMLEventReader is an event producer. StAX supports
simultaneous reading and writing, such that it is possible to read from one XML stream
sequentially and simultaneously write to another stream.
The Read-and-Write example shows how the StAX producer/consumer mechanism can be
used to read and write simultaneously. This example also shows how a stream can be modified
and how new events can be added dynamically and then written to a different stream.
Example Code
The Java EE 5 Tutorial · September 2007
578