XMLInputFactory: createXMLEventReader(Reader reader) : XMLInputFactory « javax.xml.stream « Java by API






XMLInputFactory: createXMLEventReader(Reader reader)

  



import java.io.FileReader;

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

public class Main {
  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.XMLInputFactory.IS_COALESCING
2.XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES
3.XMLInputFactory.setProperty(String name, Object value)
4.XMLInputFactory: createFilteredReader(XMLEventReader reader, EventFilter filter)
5.XMLInputFactory: createFilteredReader(XMLStreamReader reader, StreamFilter filter)
6.XMLInputFactory: createXMLEventReader(InputStream stream)
7.XMLInputFactory: createXMLStreamReader(InputStream stream)
8.XMLInputFactory: setXMLResolver(XMLResolver resolver)