FasterXML/aalto-xml — Issue #10: support for capturing  EVENT_INCOMPLETE with XMLEventReader
Author: bblfish
Created: 2012-02-01 00:30:37+00:00
State: open

I have just been trying to use Aalto's parser with Jena's RDF parsers.
I asked the Jena group what was the best way to do that and we thought that
adapting the StaX2SAX would probably do it.

http://svn.apache.org/viewvc/incubator/jena/Jena2/jena/trunk/src/main/java/com/hp/hpl/jena/rdf/arp/StAX2SAX.java?revision=1198759&view=markup

So I worked today on this and ended up with this gist

https://gist.github.com/1713430

It seems to be close to working.

but we get an exception on line 82

XMLEvent e = eventReader.nextEvent();

javax.xml.stream.XMLStreamException: Unrecognized event type 257.
at org.codehaus.stax2.ri.evt.Stax2EventAllocatorImpl.allocate(Stax2EventAllocatorImpl.java:85)
at org.codehaus.stax2.ri.Stax2EventReaderImpl.createStartDocumentEvent(Stax2EventReaderImpl.java:441)
at org.codehaus.stax2.ri.Stax2EventReaderImpl.nextEvent(Stax2EventReaderImpl.java:245)
at patch.AsyncJenaParser.parse(AsyncJenaParser.java:82)

This is I suppose because I am transforming the AsyncXMLStreamReader into an
XMLEventReader as that is the closest to the the way the Jena code was written. You can
see this in the constructor

public AsyncJenaParser(ContentHandler handler, AsyncXMLStreamReader streamReader) throws XMLStreamException {
this.handler = handler;
this.lhandler = (handler instanceof LexicalHandler) ?
(LexicalHandler) handler :
NO_LEXICAL_HANDLER ;
handler.setDocumentLocator(new LocatorConv(streamReader));
final XMLInputFactory xf = InputFactoryImpl.newInstance();
this.streamReader = streamReader;
this.eventReader = xf.createXMLEventReader(streamReader);
}

So this is not SAX parsing. It is just using an event reader instead of the stream reader. The class is used currently by the following Scala code which extends the com.ning.http.AsyncHandler

https://gist.github.com/1713663