Stax XML iterator read : Streaming XML Parser « JDK 6 « Java






Stax XML iterator read

 


import java.io.FileReader;

import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.events.XMLEvent;

public class STAXIteratorRead {
  public static void main(String args[]) throws Exception {
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    XMLEventReader xmler = xmlif.createXMLEventReader(new FileReader("yourFile.xml"));
    XMLEvent event;
    while (xmler.hasNext()) {
      event = xmler.nextEvent();
      if (event.isStartElement()) {
        System.out.println(event.asStartElement().getName());
      } else if (event.isCharacters()) {
        System.out.println(event.asCharacters().getData());
      }
    }
  }
}

        








Related examples in the same category

1.Stax XML cursor read
2.StAX is a technology similar to SAX.
3.XMLEventReader Demo
4.XMLStreamWriter Demo
5.Using XMLEventFactory to create xml document
6.Streaming XML Parser: Stax Event
7.Streaming XML Parser: Stax Event Filter
8.XMLEventReader and XMLEventWriter for Stax XML parser
9.Using XMLStreamWriter to create XML file
10.STAX cursor
11.Catch XMLStreamException
12.Get information as an XMLEvent object when using cursor approach