April 18, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Delving Deeper Into StAX, Page 4

  • June 22, 2004
  • By Jeff Ryan, Jeff Ryan
  • Send Email »
  • More Articles »

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].

Sample Code

The sample code can be downloaded here.

Summary

StAX has cursor and event based iterator APIs. There are both reading and writing sides of the API. We reviewed code snippets of all the API, and built classes for reading and writing documents using the event API. We discussed why there are two types of StAX API, and why you might use each. Next time, we'll discuss when it is appropriate to use SAX, DOM, TrAX, and StAX—the various API in the JAXP family. Until then, the rest is up to you!

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 jeffreyjryan@aol.com.

Other Articles Written by Jeff Ryan

 


[i] Java Community Process http://jcp.org, Streaming API for XML JSR-173 Specification Version 1.0, October 2003





Page 4 of 4



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel