The StAX stands for the “Streaming API for XML” which is used for reading and writing XML documents. It works similarly to SAX parser except the below differences.
Difference between StAX and SAX XML parser.
1. StAX is a pull API where SAX is a push API.
2. StAX can read and write XML documents where SAX can only read XML documents.
StAX is pull API:
StAX is a pull style API because it application have to move the StAX parser from element to element in the XML file i.e. application pulling the events from the parser.
StAX API categories:
1. Event Iterator API
2. Cursor API
Event Iterator API:
It acts as an iterator. Following are the Event Iterator API classes for reading and writing XML documents:
1. XMLEventReader: It is used for reading the XML documents.
2. XMLEventWriter: It is used for writing the XML documents.
Cursor API:
It acts as ResultSet. Following are the Cursor API classes for reading and writing XML documents:
1. XMLStreamReader: It is used for reading the XML documents.
2. XMLStreamWriter: It is used for writing the XML documents.
Stax xml parser examples:
Next Topic: Java StAX XMLEventReader example.
Previous Topic: SAX XML parser in java with example.