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






XMLStreamReader: getLocation()

  


import java.io.File;
import java.io.FileInputStream;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = inputFactory.createXMLStreamReader(new FileInputStream(new File("test.xml")));

    int eventTypeID = reader.nextTag();
    reader.require(XMLStreamConstants.START_ELEMENT, null, "person");

    eventTypeID = reader.nextTag();
    try {
      reader.require(XMLStreamConstants.START_ELEMENT, null, "first_name");
    } catch (XMLStreamException e) {
      System.out.println("Assertion failed. " + e.getMessage() + " at "
          + reader.getLocation().getLineNumber() + ":" + reader.getLocation().getColumnNumber());
    }
    System.out.println(reader.getElementText());

  }
}

   
    
  








Related examples in the same category

1.XMLStreamReader.getLocalName()
2.XMLStreamReader: getElementText()
3.XMLStreamReader: getEventType()
4.XMLStreamReader: getName()
5.XMLStreamReader: getText()
6.XMLStreamReader: hasNext()
7.XMLStreamReader: next()
8.XMLStreamReader: nextTag()
9.XMLStreamReader: require(int type, String namespaceURI, String localName)