开发者

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);
  xmlIn开发者_开发技巧putFactory.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 = "";
}


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.


it tells you the index of current object of the xml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜