XMLEventReader: hasNext() : XMLEventReader « javax.xml.stream « Java by API






XMLEventReader: hasNext()

  



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.XMLEventReader: nextEvent() throws XMLStreamException
2.XMLEventWriter: add(XMLEvent event) throws XMLStreamException
3.XMLEventWriter: add(XMLEventReader reader) throws XMLStreamException