Project

Profile

Help

PullToStax starts in null/0 initial state

Added by Anonymous over 15 years ago

Legacy ID: #6972603 Legacy Poster: David Lee (daldei)

PullToStax starts in an invalid (0) initial state. According to the Stax documents http://java.sun.com/javaee/5/docs/tutorial/doc/bnbem.html The initial state of an XMLStreamReader is the START_DOCUMENT state. but if you create a PullToStax then call getEventType() the initial state is 0. This causes an exception (in woodstox) when using an identity transform. That is, if I create a PullToStax instance from a document (NodeInfo) then create a STaX writer, the writer exceptions because it is requesting the initial state and is getting 0 instead of START_DOCUMENT The workaround is to call "next()" on PullToStax after initial creation which then sets the initial state correction. I do agree this is entirely weird ... but its how Stax seems to be documented and implemented. "When you create an instance of XMLStreamReader on a stream, the initial current event is the START_DOCUMENT state. The XMLStreamReader.next method can then be used to step to the next event in the stream." An example of the crash is this : I can provide full code if necessary Suppose I create a XMLEventReader and XMLEventWriter, where the XMLEventReader is created given a PullToStax instance using XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader( new PulltoStax( ... ) ); XMLEventWriter writer = XMLOutputFactor.newInstance().createXMLEventWriter( ... ); This code crashes in woodstox writer.add( reader ); This is because the first call into PullToStax is getEventType() which returns 0; If I call reader.next() before the writer.add(reader) then all works well. -David


Replies (1)

RE: PullToStax starts in null/0 initial state - Added by Anonymous over 15 years ago

Legacy ID: #6983550 Legacy Poster: Michael Kay (mhkay)

Thanks, now patched: https://sourceforge.net/tracker/?func=detail&aid=2716905&group_id=29872&atid=397617 It seems I spotted this when doing the EventToStaxBridge code which was derived from PullToStax, but failed to correct the original code. Michael Kay http://www.saxonica.com/

    (1-1/1)

    Please register to reply