Streaming API for XML

from Wikipedia, the free encyclopedia

Streaming API for XML ( StAX ) is an application programming interface (API) to process XML files from Java .

The reference implementation is available as free software under the terms of the Apache license .

technology

Traditionally, XML APIs are:

tree based
(e.g. DOM ) - the entire document is read into the memory as a tree structure and can be accessed directly from there.
event based
(e.g. SAX ) - the application receives an event when new entities are discovered in the document.

Both variants have advantages and disadvantages: the first allows random access to the document, but has to keep the document in memory and therefore requires more memory. The second is a single pass through the source document and therefore hardly requires any memory and is also faster when parsing, but does not allow direct access to elements or changes in the tree.

StAX was designed as a middle ground between these two opposites. In the StAX metaphor, the programmatic entry is a cursor that represents a point in the document. The application moves the cursor forward, so it gets the information it needs from the parser exactly when it is needed. This differs from an event-based API such as SAX, which actively sends the data into the application and thus forces the application to manage status information between events in order to record the current position in the document.

In addition to access to the XML data via a cursor, StAX also offers an iterator method. The iterator method supplies the data in the form of objects that are derived from the XMLEvent class. The objects created offer the Java developer more options than the string objects in the cursor method, but they reduce performance.

Alongside DOM, SAX and XSLT, StAX is one of the interfaces of the Java API for XML Processing .

Origins

StAX has its roots in a whole range of event-driven programming interfaces, primarily "XMLPULL", the authors of which ( Stefan Haustein and Aleksandr Slominski ) worked with BEA , Oracle , Sun Microsystems , Breeze Factor and James Clark , among others .

Web links