Streaming API for XML (StAX) is an application programming interface (API) to read and write XML documents in the Java programming language.

Traditionally, XML APIs are either:
* tree 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. Both have advantages; the former (for example, DOM) allows for random access to the document, the latter (e.g. SAX) requires a small memory footprint and is typically much faster.

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.


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 Systems, Oracle, Sun, [ Breeze Factor] and James Clark.


From JSR-173 Specification• Final, V1.0 (used under fair use).

Quote::The following Java API shows the main methods for reading XML in the cursor approach. // Java public interface XMLStreamReader { public int next() throws XMLStreamException; public boolean hasNext() throws XMLStreamException; public String getText(); public String getLocalName(); public String getNamespaceURI(); // ...othermethodsnotshown } :The writing side of the API has methods that correspond to the reading side for “StartElement” and “EndElement” event types. // Java public interface XMLStreamWriter { public void writeStartElement(String localName) throws XMLStreamException; public void writeEndElement() throws XMLStreamException; public void writeCharacters(String text) throws XMLStreamException; // ...othermethodsnotshown } :5.3.1 XMLStreamReader :This example illustrates how to instantiate an input factory, create a reader and iterate over the elements of an XML document. XMLInputFactory f = XMLInputFactory.newInstance(); XMLStreamReader r = f.createXMLStreamReader(... ); while (r.hasNext()) {; }


* Reference Implementation
* [ Woodstox] Open source StAX implementation
* is Sun's Stax implementation


* The video game FreeCol uses the StAX API and the Woodstox implementation as the XML parser for its game data.

See also

Competing and complementary ways to process XML in Java (ordered loosely based on initial date of introduction):
* DOM Document Object Model is the first standardized, language/platform-independent tree-based xml processing model. (note: there are also alternate Java tree models like JDOM, Dom4j, XOM).
* SAX The standard "XML push" API
* JAXB Java XML Binding API: works on top of another parser (usually streaming parser), binds contained data to/from Java objects.
* Javolution provides a real-time StAX-like [ implementation] which does not force object creation (e.g. String) and has smaller effect on memory footprint/garbage collection (Note: to reduce object creation, most StAX implementations maintain lookup tables to retrieve and reuse frequently used String objects).

External links

* [ Introduction to StAX], Harold, Elliotte Rusty
* [ Java Streaming API for XML (Stax) - Tutorial]
* [ JSR (#173)] :Download JSR specification document as a pdf here: [ download now]
* [] Articles and resources from Aleksander Slominski.
** [ ~aslom/xmlpull/patterns.html] Article on XML Pull (and StAX) design patterns (recommended).
* []
* [ StAX and Sax comparison.]
* [ Using StAX with JAXB for efficiency]
* [ StAX and Java eg. from]
* [ StAX-Utils] Provides a set of utility classes that make it easy for developers to integrate StAX into their existing XML processing applications.
** StAX-Utils includes classes to provide XML file indenting and formatting.
* [ StaxMate] is a light-weight framework that builds on top of Stax API and provides more convenient nested/filtered cursor for reading xml, and nested outputters for writing xml.

Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Stax — Records Filiale de Fondé en 1957 Fondateur Jim Stewart Estelle Axton Statut Fermé en 1975 Maison de di …   Wikipédia en Français

  • Stax — Saltar a navegación, búsqueda Stax fue una de las más importantes compañías discográficas de la historia de la música soul, contemporánea de la archipopular Motown. Irónicamente, ésta, una de las más importantes compañías de música negra, la creó …   Wikipedia Español

  • Stax — can refer to:* Stax Earspeakers, a Japanese brand of electrostatic earspeakers * Stax Records, an American record company based out of Memphis, Tennessee * StAX, Streaming API for XML * Lay s Stax, a brand of potato snack chips sold by Lay s …   Wikipedia

  • Stax — bezeichnet einen japanischen Hersteller von elektrostatischen Kopfhörern, siehe Stax Ltd. ein Musiklabel, siehe Stax Records eine pullbasierte Streaming API für XML ein US amerikanisches Brettspiel (Plagiat von Laska) …   Deutsch Wikipedia

  • StAX — Streaming API for XML (StAX) ist ein Application Programming Interface (API), um XML Dateien aus Java zu verarbeiten. Traditionellerweise sind XML APIs: baumbasiert – das gesamte Dokument wird als Baumstruktur in den Speicher gelesen und kann von …   Deutsch Wikipedia

  • StAX — Streaming API for XML Streaming API for XML ou StAX est une API permettant d exploiter les documents XML. Tout comme SAX, StAX n encombre pas la mémoire et le document est lu linéairement, mais c est l application qui tire explicitement l… …   Wikipédia en Français

  • stax — ap·o·stax·is; ep·i·stax·is; …   English syllables

  • STAX — Stelax Industries, LTD. (Business » NASDAQ Symbols) * OCI Chemical Corporation (Regional » Railroads) * Simple Typed Api For Xml (Computing » General) …   Abbreviations dictionary

  • STAX — Standards TAXonomy (RACE Database) …   Acronyms

  • STAX — Standards TAXonomy (RACE Database) …   Acronyms von A bis Z