0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.