KItis
KItis

Reputation: 5646

what is the purpose of getEventType() method in XMLStreamReader Class

I have sample code written for parsing xml file using javax.xml package. it uses the method called getEventType() , but I can not understand the purpose of this method.

i wrote simple application to understand its usefulness, but it output only some random numbers for which I can not make any sense, could some one help me to get this point right.

Here is the sample code I have written.

public List parseXML(File f) throws XMLStreamException{
  xmlInputFactory = new WstxInputFactory();

  xmlInputFactory.setProperty(XMLInputFactory2.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
  xmlInputFactory.setProperty(XMLInputFactory2.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
  xmlInputFactory.setProperty(XMLInputFactory2.IS_COALESCING,Boolean.FALSE);
  xmlInputFactory.setProperty(XMLInputFactory2.IS_VALIDATING,Boolean.FALSE);
  xmlInputFactory.configureForSpeed();

  List<Task> tasks = new LinkedList<Task>();

  //xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(dmml));
  xmlStreamReader = xmlInputFactory.createXMLStreamReader(f);

  int eventType = xmlStreamReader.getEventType();
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  eventType = xmlStreamReader.next();
  System.out.println(eventType);
  /*String currentElement = "";
  String currentElementText = "";
}

Upvotes: 1

Views: 6099

Answers (2)

Muhammad Naveed
Muhammad Naveed

Reputation: 201

it tells you the index of current object of the xml

Upvotes: 1

skaffman
skaffman

Reputation: 403551

The event types tell you what sort of entity the parser is currently pointed at, for example is it a element start tag, and end tag, an attribute, and so on.

The event types are defined in the javadoc. They're all defined as int, so you need to use the table in the javadoc to understand what they mean. The actual numeric values are listed in XMLStreamConstants. However, the numeric values are not interesting in themselves, you should use the XMLStreamConstants-defined constants by name.

Upvotes: 2

Related Questions