background image

readnwrite Sample

<< Capturing the Event Stream | Creating an Event Producer >>
<< Capturing the Event Stream | Creating an Event Producer >>
READNWRITE
S
AMPLE
­ E
VENT
P
RODUCER
C
ONSUMER
.
JAVA
111
Running the Sample
When you run the
MyStreamFilter
sample, the class is compiled, and the XML
stream is parsed as events and returned to
STDOUT
. For example an
Author
event
is returned as follows:
EVENT TYPE(1):START_ELEMENT
HAS NAME: Author
HAS NO TEXT
HAS NO ATTRIBUTES
-----------------------------
EVENT TYPE(2):END_ELEMENT
HAS NAME: Author
HAS NO TEXT
-----------------------------
Similarly, a
Cost
event is returned as follows:
EVENT TYPE(1):START_ELEMENT
HAS NAME: Cost
HAS NO TEXT
HAS ATTRIBUTES:
ATTRIBUTE-PREFIX:
ATTRIBUTE-NAMESP: null
ATTRIBUTE-NAME: currency
ATTRIBUTE-VALUE: USD
ATTRIBUTE-TYPE: CDATA
-----------------------------
EVENT TYPE(2):END_ELEMENT
HAS NAME: Cost
HAS NO TEXT
-----------------------------
See earlier in this chapter, in the "Iterator API" and "Reading XML Streams"
sections, for a more detailed discussion of StAX event parsing.
readnwrite Sample ­
EventProducerConsumer.java
Located in the
<javaee.tutorial.home>/examples/stax/
readnwrite direc-
tory,
EventProducerConsumer.java
demonstrates how to use a StAX parser
simultaneously as both a producer and a consumer.