StAX is a technology similar to SAX. : Stream Parser « XML « Java Tutorial

StAX is based on a pull technology.

StAX is the client that queries the StAX parser for more elements.

It allows you to iterate over the elements being read, similar to having a ResultSet in a JDBC application.

StAX classes and interfaces are in package and its two subpackages, and

The four most prominent interfaces are XMLStreamReader, XMLEventReader, XMLStreamWriter, and XMLEventWriter, all of which are part of



public class XMLStreamReaderDemo {
  public static void main(String[] args) throws Exception {
    XMLInputFactory factory = XMLInputFactory.newInstance();

    Reader fileReader = new FileReader("source.xml");
    XMLStreamReader reader = factory.createXMLStreamReader(fileReader);

    while (reader.hasNext()) {

  private static void process(XMLStreamReader reader) {
    int eventType = reader.getEventType();
    switch (eventType) {
    case XMLStreamConstants.START_ELEMENT:
      System.out.println("Start element: " + reader.getLocalName());

      int count = reader.getAttributeCount();
      for (int i = 0; i < count; i++) {
        String name = reader.getAttributeLocalName(i);
        String value = reader.getAttributeValue(i);
        System.out.println("\tAttribute name/value: " + name + "/" + value);

    case XMLStreamConstants.END_ELEMENT:
      System.out.println("End element: " + reader.getLocalName());

    case XMLStreamConstants.CHARACTERS:
      System.out.println("Text: " + reader.getText());

33.8.Stream Parser
33.8.1.StAX is a technology similar to SAX.
33.8.2.XMLEventReader Demo
33.8.3.XMLStreamWriter Demo
33.8.4.Using XMLEventFactory to create xml document
33.8.5.Streaming XML Parser: Stax Event
33.8.6.Streaming XML Parser: Stax Event Filter
33.8.7.XMLEventReader and XMLEventWriter for Stax XML parser
33.8.8.Using XMLStreamWriter to create XML file
33.8.9.STAX cursor
33.8.10.Catch XMLStreamException
33.8.11.Get information as an XMLEvent object when using cursor approach
33.8.12.Stax XML iterator read
33.8.13.Stax XML cursor read
33.8.14.Read Xml from StreamSource
33.8.15.Validate Stax