XMLStreamReader: getName() : XMLStreamReader « javax.xml.stream « Java by API






XMLStreamReader: getName()

  


import java.io.FileReader;

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

public class Main {
  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.XMLStreamReader.getLocalName()
2.XMLStreamReader: getElementText()
3.XMLStreamReader: getEventType()
4.XMLStreamReader: getLocation()
5.XMLStreamReader: getText()
6.XMLStreamReader: hasNext()
7.XMLStreamReader: next()
8.XMLStreamReader: nextTag()
9.XMLStreamReader: require(int type, String namespaceURI, String localName)