StAX
Streaming API for XML is an application programming interface to read and write XML documents, originating from the Java programming language community.
Traditionally, XML APIs are either:
- DOM based - the entire document is read into memory as a tree structure for random access by the calling application
- event based - the application registers to receive events as entities are encountered within the source document.
These two access metaphors can be thought of as polar opposites. A tree based API allows unlimited, random access and manipulation, while an event based API is a 'one shot' pass through the source document.
StAX was designed as a median between these two opposites. In the StAX metaphor, the programmatic entry point is a cursor that represents a point within the document. The application moves the cursor forward - 'pulling' the information from the parser as it needs. This is different from an event based API - such as SAX - which 'pushes' data to the application - requiring the application to maintain state between events as necessary to keep track of location within the document.
Origins
StAX has its roots in a number of incompatible pull APIs for XML, most notably, the authors of which collaborated with, amongst others, BEA Systems, Oracle, Sun and James Clark.Examples
From JSR-173 Specification• Final, V1.0.Quote:
public interface XMLStreamReader
public interface XMLStreamWriter
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance;
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader;
while )