Reputation: 605
I know how to utilize java stax iterator api's to read an xml document, but i would like to understand the implementation of XMLEvent and XMLEventReader.
XMLInputFactory xmlInFactory = XMLInputFactory.newFactory();
FileInputStream inStream = new FileInputStream(inFileName);
XMLEventReader xmlEventReader = xmlInFactory.createXMLEventReader(inStream);
while(xmlEventReader.hasNext()){
xmlEvent = xmlEventReader.nextEvent();
if(xmlEvent.isStartElement()){
startElement = xmlEvent.asStartElement();
---more code---
}
}
As both XMLEventReader & XMLEvent are interfaces, where is the implementation for hasNext(), isStartElement() & asStartElement() methods? How are these methods working without method implementation in JDK? Where is this logic coming from?
Thank you for your help in advance.
Upvotes: 0
Views: 200
Reputation: 163458
As these are interfaces, there can be multiple implementations. For example in my development environment I have several implementations of XMLEventReader available, including for example:
com.sun.xml.stream.XMLEventReaderImpl
org.codehaus.stax2.XMLEventReader2
The first of these is the Sun pull XML parser, which is distributed in the JDK; the second is part of the third-party Woodstox parser.
Upvotes: 1