background image

Returning the Output

<< Creating an Event Producer Consumer | Creating a Stream Writer >>
<< Creating an Event Producer Consumer | Creating a Stream Writer >>

Returning the Output

Returning the Output
When you run the Read-and-Write example, the EventProducerConsumer class is compiled,
and the XML stream is parsed as events and written back to STDOUT. The output is the contents
of the BookCatalog.xml file described in
"Example XML Document" on page 568
.
Building and Running the Read-and-Write Example Using NetBeans
IDE
Follow these instructions to build and run the Read-and-Write 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 readnwrite folder.
4. Select the Open as Main Project check box.
5. Click Open Project Folder.
6. In the Projects tab, right-click the readnwrite project and select Properties. The Project
Properties dialog is displayed.
7. Enter the following in the Arguments field:
BookCatalog.xml
8. Click OK.
9. Right-click the readnwrite project and select Run Project.
Building and Running the Read-and-Write Example Using Ant
To compile and run the Read-and-Write example using Ant, in a terminal window, go to the
tut-install/javaeetutorial5/examples/stax/readnwrite/ directory and type the following:
ant run-readnwrite
Writer Example
Located in the tut-install/javaeetutorial5/examples/stax/writer/ directory,
CursorWriter.java
demonstrates how to use the StAX cursor API to write an XML stream.
Creating the Output Factory
The first step is to create an instance of XMLOutputFactory:
XMLOutputFactory xof =
XMLOutputFactory.newInstance();
Example Code
The Java EE 5 Tutorial · September 2007
580