10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Example Code<br />

578<br />

Returning the Output<br />

When you run the Read-and-Write example, the EventProducerConsumer class is compiled,<br />

and the XML stream is parsed as events and written back to STDOUT. <strong>The</strong> output is the contents<br />

of the BookCatalog.xml file described in “Example XML Document” on page 566.<br />

Building and Running the Read-and-Write Example Using NetBeans<br />

IDE<br />

Follow these instructions to build and run the Read-and-Write example on your Application<br />

Server instance using NetBeans IDE.<br />

1. In NetBeans IDE, select File→Open Project.<br />

2. In the Open Project dialog, navigate to the tut-install/javaeetutorial5/examples/stax/<br />

directory.<br />

3. Select the readnwrite folder.<br />

4. Select the Open as Main Project check box.<br />

5. Click Open Project.<br />

6. In the Projects tab, right-click the readnwrite project and select Properties. <strong>The</strong> Project<br />

Properties dialog is displayed.<br />

7. Enter the following in the Arguments field:<br />

BookCatalog.xml<br />

8. Click OK.<br />

9. Right-click the readnwrite project and select Run.<br />

Building and Running the Read-and-Write Example Using Ant<br />

To compile and run the Read-and-Write example using Ant, in a terminal window, go to the<br />

tut-install/javaeetutorial5/examples/stax/readnwrite/ directory and type the following:<br />

ant run-readnwrite<br />

Writer Example<br />

Located in the tut-install/javaeetutorial5/examples/stax/writer/ directory,<br />

CursorWriter.java demonstrates how to use the StAX cursor API to write an XML stream.<br />

Creating the Output Factory<br />

<strong>The</strong> first step is to create an instance of XMLOutputFactory:<br />

XMLOutputFactory xof = XMLOutputFactory.newInstance();<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!