Stax Records Albums
   HOME

TheInfoList



OR:

Streaming API for XML (StAX) is an application programming interface (
API An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standa ...
) to read and write
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. T ...
documents, originating from the
Java programming language Java is a high-level, class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let programmers ''write once, run anywh ...
community. Traditionally, XML APIs are either: * DOM based - the entire document is read into memory as a
tree structure A tree structure, tree diagram, or tree model is a way of representing the hierarchical nature of a structure in a graphical form. It is named a "tree structure" because the classic representation resembles a tree, although the chart is gener ...
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:
DOM Dom or DOM may refer to: People and fictional characters * Dom (given name), including fictional characters * Dom (surname) * Dom La Nena (born 1989), stage name of Brazilian-born cellist, singer and songwriter Dominique Pinto * Dom people, an et ...
, for example, allows for random access to the document, and event driven algorithm like SAX has 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.


Origins

StAX has its roots in a number of incompatible pull APIs for XML, most notabl
XMLPULL
the authors of which (Stefan Haustein and Aleksander Slominski) collaborated with, amongst others,
BEA Systems BEA Systems, Inc. was a company that specialized in enterprise infrastructure software products which was wholly acquired by Oracle Corporation on April 29, 2008. History BEA began as a software company, founded in 1995 and headquartered in ...
,
Oracle An oracle is a person or agency considered to provide wise and insightful counsel or prophetic predictions, most notably including precognition of the future, inspired by deities. As such, it is a form of divination. Description The word '' ...
,
Sun The Sun is the star at the center of the Solar System. It is a nearly perfect ball of hot plasma, heated to incandescence by nuclear fusion reactions in its core. The Sun radiates this energy mainly as light, ultraviolet, and infrared radi ...
and James Clark.


Examples

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. public interface XMLStreamReader :The writing side of the API has methods that correspond to the reading side for “StartElement” and “EndElement” event types. public interface XMLStreamWriter :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 xmlInputFactory = XMLInputFactory.newInstance(); XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(...); while (xmlStreamReader.hasNext())


See also

Competing and complementary ways to process XML in Java (the order is loosely based on initial date of introduction): * Document Object Model (DOM), the first standardized, language/platform-independent tree-based XML processing model; alternate Java tree models include
JDOM JDOM is an open-source Java-based document object model for XML that was designed specifically for the Java platform so that it can take advantage of its language features. JDOM integrates with Document Object Model (DOM) and Simple API for X ...
,
Dom4j dom4j is an open-source Java library for working with XML, XPath and XSLT. It is compatible with DOM, SAX and JAXP In computing, the Java API for XML Processing, or JAXP ( ), one of the Java XML Application programming interfaces, provides ...
, and XOM * Simple API for XML (SAX), the standard XML push API * Java XML Binding API (JAXB), works on top of another parser (usually streaming parser), binds contained data to/from Java objects. *
Streaming XML Streaming XML is a synonym for dynamic data in XML format. Another popular use of this term refers to one method of consuming XML data – largely known as Simple API for XML. This is via asynchronous events that are generated as the XML data is ...
*
XQuery API for Java XQuery API for Java (XQJ) refers to the common Java API for the W3C XQuery 1.0 specification. The XQJ API enables Java programmers to execute XQuery against an XML data source (e.g. an XML database) while reducing or eliminating Vendor lock-i ...


External links


Introduction to StAX
XML.com, Harold, Elliotte Rusty



Article on XML Pull (and StAX) design patterns by Aleksander Slominski.
StAX Parser - Cursor & Iterator APIs
Article on Cursor & Iterator APIs by HowToDoInJava. {{Java EE 7 Java platform Application programming interfaces XML parsers Articles with example Java code