I'm facing a weird runtime conflict between Woodstox STAX and java 1.6 STAX implementation. Since I'm using CXF,its pulling Woodstox jar as part of its dependency. Here's a sample code I'm using.
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.events.Attribute;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
XMLInputFactory factory = (XMLInputFactory)XMLInputFactory.newInstance();
XMLEventReader reader =
factory.createXMLEventReader(new StringReader(xml));
while (reader.hasNext()){
XMLEvent event = reader.nextEvent();
switch (event.getEventType()){
case XMLEvent.START_ELEMENT :
StartElement se = event.asStartElement();
...........
...........
case XMLEvent.END_ELEMENT :
EndElement endElement = event.asEndElement();
if (event.asEndElement().getName().getLocalPart()==("document"))
// do something
During runtime, I'm getting the following exception.
java.lang.Exception: java.lang.ClassCastException: com.ctc.wstx.evt.CompactStartElement cannot be cast to javax.xml.stream.events.EndElement
when it reaches line EndElement endElement = event.asEndElement();
I'm sort of puzzled why its causing at this point though it doesn't fail in
StartElement se = event.asStartElement();
While debugging, I found that the event objects are part of com.ctc.wstx.evt package and not javax.xml.stream. But not sure why its not failing before.
Any pointer will be highly appreciated.