background image

Sample Code Organization

<< SJSXP Factories Implementation | Configuring Your Environment >>
<< SJSXP Factories Implementation | Configuring Your Environment >>
S
AMPLE
C
ODE
99
Sample Code
This section steps through the sample StAX code included in the J2EE 1.4 Tuto-
rial bundle. All sample directories used in this section are located off the
<jav-
aee.tutorial.home>/examples/stax
directory.
The topics covered in this section are as follows:
· Sample Code Organization (page 99)
· Configuring Your Environment for Running the Samples (page 100)
· Running the Samples (page 101)
· Sample XML Document (page 102)
· cursor Sample ­ CursorParse.java (page 103)
· cursor2event Sample ­ CursorApproachEventObject.java (page 105)
· event Sample ­ EventParse.java (page 106)
· filter Sample ­ MyStreamFilter.java (page 109)
· readnwrite Sample ­ EventProducerConsumer.java (page 111)
· writer Sample ­ CursorWriter.java (page 114)
Sample Code Organization
There are seven StAX sample directories in
<javaee.tutorial.home>/exam-
ples/stax
:
·
common
contains a
build.properties
file and a
target.xml
file that are
used commonly by all the StAX tutorial examples. There is also a
data
directory containing a sample XML document,
BookCatalog.xml
, that is
used by all the StAX examples. The values in
common/build.properties
as well as all the StAX examples are inherited from a parent
build.prop-
erties
file in the
<javaee.tutorial.home>/examples/common
direc-
tory. Note that you should not need to modify the
build.properties
file
in
stax/common/build.properties
.
·
cursor
contains
CursorParse.java
, which illustrates how to use the
XML-
StreamReader
(cursor) API to read an XML file.
·
cursor2event
contains
CursorApproachEventObject.java
, which illus-
trates how an application can get information as an
XMLEvent
object when
using cursor API.