The Java EE 5 Tutorial

Example of Event Mapping

As an example of how the event iterator API maps an XML stream, consider the following XML document:

<?xml version="1.0"?>
<BookCatalogue xmlns="http://www.publishing.org">
    <Book>
        <Title>Yogasana Vijnana: the Science of Yoga</Title>
        <ISBN>81-40-34319-4</ISBN>
        <Cost currency="INR">11.50</Cost>
    </Book>
</BookCatalogue>

This document would be parsed into eighteen primary and secondary events, as shown in Table 18–3. Note that secondary events, shown in curly braces ({}), are typically accessed from a primary event rather than directly.

Table 18–3 Example of Iterator API Event Mapping

# 

Element/Attribute 

Event 

1 

version="1.0"

StartDocument

2 

isCData = false
data = "\n"
IsWhiteSpace = true

Characters

3 

qname = BookCatalogue:http://www.publishing.org
attributes = null
namespaces = {BookCatalogue" -> http://www.publishing.org"}

StartElement

4 

qname = Book
attributes = null
namespaces = null

StartElement

5 

qname = Title
attributes = null
namespaces = null

StartElement

6 

isCData = false
data = "Yogasana Vijnana: the Science of Yoga\n\t"
IsWhiteSpace = false

Characters

7 

qname = Title
namespaces = null

EndElement

8 

qname = ISBN
attributes = null
namespaces = null

StartElement

9 

isCData = false
data = "81-40-34319-4\n\t"
IsWhiteSpace = false

Characters

10 

qname = ISBN
namespaces = null

EndElement

11 

qname = Cost
attributes = {"currency" -> INR}
namespaces = null

StartElement

12 

isCData = false
data = "11.50\n\t"
IsWhiteSpace = false

Characters

13 

qname = Cost
namespaces = null

EndElement

14 

isCData = false
data = "\n"
IsWhiteSpace = true

Characters

15 

qname = Book
namespaces = null

EndElement

16 

isCData = false
data = "\n"
IsWhiteSpace = true

Characters

17 

qname = BookCatalogue:http://www.publishing.org
namespaces = {BookCatalogue" -> http://www.publishing.org"}

EndElement

18 

 

EndDocument

There are several important things to note in this example: