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






Stax XML cursor read

 


import java.io.FileReader;

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

public class STAXCursorRead {
  public static void main(String args[]) throws Exception {
    XMLInputFactory xmlif = XMLInputFactory.newInstance();
    XMLStreamReader xmlsr = xmlif.createXMLStreamReader(new FileReader("points.xml"));
    int eventType;
    while (xmlsr.hasNext()) {
      eventType = xmlsr.next();
      switch (eventType) {
      case XMLEvent.START_ELEMENT:
        System.out.println(xmlsr.getName());
        break;
      case XMLEvent.CHARACTERS:
        System.out.println(xmlsr.getText());
        break;
      default:
        break;
      }
    }
  }
}

        








Related examples in the same category

1.Stax XML iterator 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