Streaming API for XML
Streaming API for XML (StAX) ist ein Application Programming Interface (API) um XML-Dateien aus Java zu verarbeiten.
Traditioneller weise sind XML APIs:
- baum basiert - Das gesammte Dokument wird als Baumstruktur in den Speicher gelesen und kann von dort direkt zugegriffen werden.
- event basiert - Die anwendungen bekommt ein Event, wenn neue Entities im Dokument entdekt werden.
Beides hat Vorteile; das Erste (z.B.: DOM) erlaubt wahlfreien Zugriff auf das Dokument, das Zweite (z.B.: SAX) benötigt wenig Speicher und ist daher üblicherweise viel schneller.
Diese zwei Arten sind das genaue gegenteil voneinander. Eine baum basierte API erlaubt unlimitierte, direkten Zugriff und Änderung, während eine event basierende API ein einmaliger Durchlauf durcht das Quelldokument ist.
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 XMLPULL, the authors of which (Stefan Haustein and Aleksandr Slominski) collaborated with, amongst others BEA, Oracle, Sun, Breeze Factor and James Clark.