Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

Iterator API

The StAX iterator is an alternative to the cursor API. A StAX iterator treats an XML document stream as a set of event objects. These events are pulled by the application and delivered by the parser in the order in which they appear in the XML document. The main parser interface for reading iterator events is XMLEventReader. For writing iterator events, you use XMLEventWriter.

Focusing on reading, the XMLEventReader interface inherits from java.util.Iterator. The workhorse method of the interface is nextEvent(), which returns the next XMLEvent in an XML stream. The interface for XMLReader looks like this:

public interface XMLEventReader extends Iterator {
 public XMLEvent nextEvent() throws XMLStreamException;
 public boolean hasNext();
 public XMLEvent peek() throws XMLStreamException;
 ...
}
  • + Share This
  • 🔖 Save To Your Account