background image

Building and Running the Event Example

<< Returning the Output | Creating the Filter >>
<< Returning the Output | Creating the Filter >>

Building and Running the Event Example

Building and Running the Event Example Using NetBeans IDE
Follow these instructions to build and run the Event 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 event folder.
4. Select the Open as Main Project check box.
5. Click Open Project Folder.
6. In the Projects tab, right-click the event 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 event project and select Run Project.
Building and Running the Event Example Using Ant
To compile and run the Event example using Ant, in a terminal window, go to the
tut-install/javaeetutorial5/examples/stax/event/ directory and type the following:
ant run-event
Filter Example
Located in the tut-install/javaeetutorial5/examples/stax/filter/ directory,
MyStreamFilter.java
demonstrates how to use the StAX stream filter API to filter out events
not needed by your application. In this example, the parser filters out all events except
StartElement
and EndElement.
Implementing the StreamFilter Class
The MyStreamFilter class implements javax.xml.stream.StreamFilter:
public class MyStreamFilter
implements javax.xml.stream.StreamFilter {
Creating an Input Factory
The next step is to create an instance of XMLInputFactory. In this case, various properties are
also set on the factory:
Example Code
Chapter 18 · Streaming API for XML
575