Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 10. Streaming API for XML

Chapter 10. Streaming API for XML

Prior to the Streaming API for XML (StAX), defined in JSR 173 (http://jcp.org/en/jsr/detail?id=173), to handle XML Java programmers had to work with the two main APIs for XML processing, DOM and SAX. DOM is easy to use and provides you with the ability to convert XML into a tree of objects. The downside is, however, the fact that DOM is inefficient for large XML documents since the whole object tree must be loaded into memory. The event-based SAX is more efficient in terms of memory usage as it does not have to load the whole XML document into memory. In fact, SAX, though harder to program, is fast and can work well with any size of documents. SAX is based on the Observer design pattern, it calls the appropriate listener as it encounters various elements of an XML document. This is a push technology in action. The problem with SAX is that data pushing is not always the perfect solution with all clients. Sometimes, the client, rather than the parser, needs to control the parsing process. In addition, SAX can only be used to read, not write.

Then came StAX. It is a technology similar to SAX, except that StAX is based on a pull technology. It is the client that queries the StAX parser for more elements. It allows you to iterate over the elements being read, similar to having a ResultSet in a JDBC application.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial