background image

Example of Event Mapping

<< Iterator Event Types | Iterator API Event Mapping >>
<< Iterator Event Types | Iterator API Event Mapping >>

Example of Event Mapping

TABLE 18­2
XMLEvent
Types
(Continued)
Event Type
Description
EntityReference
Character entities can be reported as discrete events, which an application
developer can then choose to resolve or pass through unresolved. By default,
entities are resolved. Alternatively, if you do not want to report the entity as an
event, replacement text can be substituted and reported as Characters.
ProcessingInstruction
Reports the target and data for an underlying processing instruction.
Comment
Returns the text of a comment.
EndDocument
Reports the end of a set of XML events.
DTD
Reports as java.lang.String information about the DTD, if any, associated
with the stream, and provides a method for returning custom objects found in the
DTD.
Attribute
Attributes are generally reported as part of a StartElement event. However, there
are times when it is desirable to return an attribute as a standalone Attribute
event; for example, when a namespace is returned as the result of an XQuery or
XPath
expression.
Namespace
As with attributes, namespaces are usually reported as part of a StartElement,
but there are times when it is desirable to report a namespace as a discrete
Namespace
event.
Note that the DTD, EntityDeclaration, EntityReference, NotationDeclaration, and
ProcessingInstruction
events are only created if the document being processed contains a
DTD.
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.
StAX API
Chapter 18 · Streaming API for XML
555