Skip to main content

OSX:Java1.6:StAX:java.lang.ClassCastException

No replies
ameremortal
Offline
Joined: 2010-03-05
Points: 0

I am using StAX to process my XML and getting the following exception:

java.lang.ClassCastException: com.sun.xml.internal.stream.events.StartDocumentEvent cannot be cast to javax.xml.stream.events.StartElement
at com.sun.xml.internal.stream.events.DummyEvent.asStartElement(DummyEvent.java:124)

This is my code:

XMLInputFactory xmlfactory = XMLInputFactory.newInstance ( );
XMLEventReader xmlReader = null;
XMLEventReader delegateXmlReader = null;
try
{
xmlReader = xmlfactory.createXMLEventReader ( aDrawingContent );

delegateXmlReader = new EventReaderDelegate ( xmlReader )
{

public XMLEvent nextEvent ( ) throws XMLStreamException
{
XMLEvent event = null;

event = super.nextEvent ( );

if ( event.isStartDocument ( ) )
{
StartElement startElement = event.asStartElement ( ); //IT FAILS HERE }

return event;
}

};

while ( delegateXmlReader.hasNext ( ) )
{
XMLEvent event = delegateXmlReader.nextEvent ( );
event.writeAsEncodedUnicode ( outputWriter );
}

xmlReader.close ( );
delegateXmlReader.close ( );
}
catch ( XMLStreamException e )
{
final String ERROR_MSG = "";
logger.error ( ERROR_MSG, e );
}

Frankly speaking, DummyEvent class found under classes.jar of JDK 1.6 on OSX 10.6.2 scares me a little bit. Never thought JAXP RI should contain dummy classes.

I would really appreciate any help.

Thanks,
Doba