background image

Example XML Document

<< Example Code | Stepping through Events >>
<< Example Code | Stepping through Events >>

Example XML Document

Filter example
: The filter directory contains MyStreamFilter.java, which illustrates
how to use the StAX Stream Filter APIs. In this example, the filter accepts only
StartElement
and EndElement events, and filters out the remainder of the events.
Read-and-Write example
: The readnwrite directory contains
EventProducerConsumer.java
, which illustrates how the StAX producer/consumer
mechanism can be used to simultaneously read and write XML streams.
Writer example
: The writer directory contains CursorWriter.java, which illustrates how
to use XMLStreamWriter to write an XML file programatically.
All of the StAX examples except for the Writer example use an example XML document,
BookCatalog.xml
.
Example XML Document
The example XML document, BookCatalog.xml, used by most of the StAX example classes, is a
simple book catalog based on the common BookCatalogue namespace. The contents of
BookCatalog.xml
are listed below:
<?xml version=
"1.0" encoding="UTF-8"?>
<BookCatalogue xmlns=
"http://www.publishing.org">
<Book>
<Title>Yogasana Vijnana: the Science of Yoga</Title>
<author>Dhirendra Brahmachari</Author>
<Date>1966</Date>
<ISBN>81-40-34319-4</ISBN>
<Publisher>Dhirendra Yoga Publications</Publisher>
<Cost currency=
"INR">11.50</Cost>
</Book>
<Book>
<Title>The First and Last Freedom</Title>
<Author>J. Krishnamurti</Author>
<Date>1954</Date>
<ISBN>0-06-064831-7</ISBN>
<Publisher>Harper &amp; Row</Publisher>
<Cost currency=
"USD">2.95</Cost>
</Book>
</BookCatalogue>
Cursor Example
Located in the tut-install/javaeetutorial5/examples/stax/cursor/ directory,
CursorParse.java
demonstrates using the StAX cursor API to read an XML document. In the
Cursor example, the application instructs the parser to read the next event in the XML input
stream by calling <code>next()</code>.
Example Code
The Java EE 5 Tutorial · September 2007
568