Delving Deeper Into StAX
When to Use a Cursor or Event Iterator API
The cursor API is less verbose and less powerful than the event API. Presumably, it is more efficient at what it does and creates fewer temporary objects. Both the cursor and event iterator API are forward only API. However, the event iterator API provides a peek() feature to get the next event, as was demonstrated in SimpleXmlEventWriter. The event iterator API has many other capabilities that we didn't cover here, such as the ability to filter, buffer, persist, and compare events[i].
The sample code can be downloaded here.
About the Author
Jeff Ryan is an enterprise architect for Hartford Financial Services. He has twenty years experience designing, developing, and delivering automated solutions to business problems. His current focus is on Java, XML, and Service Oriented Architecture. He may be reached at email@example.com.
[i] Java Community Process http://jcp.org, Streaming API for XML JSR-173 Specification Version 1.0, October 2003
Page 4 of 4