Project

Profile

Help

IllegalStateException using EventToStaxBridge

Added by Anonymous about 15 years ago

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

I know this is "internal" code in saxon but you suggested at one point I try it so here's my success (not). I'm trying to make a Stax Event or Stream reader out of a XdmNode. Here's the code I 'm using to make a Stax Stream reader, following the guideline of the test main commented out in EventToStaxBridge. public XMLStreamReader asXMLStreamReader(SerializeOpts opts) throws InvalidArgumentException, CoreException, XMLStreamException { // See EventToStaxBridge Configuration config = Shell.getProcessor().getUnderlyingConfiguration(); PipelineConfiguration pipe = config.makePipelineConfiguration(); pipe.setHostLanguage(Configuration.XQUERY); Decomposer iter = new Decomposer( mVariable.getValue().asNodeInfo() , pipe); XMLStreamReader sr = new EventToStaxBridge(iter, config.getNamePool()); return sr; } ========= For very very simple nodes, such as the output of xquery on "<foo/>" it works. But if I build a node from a real document (using the S9 Builder) and try this I consistently get an exception. The exception is from here : TinyTreeEventIterator.java case Type.PARENT_POINTER: throw new IllegalStateException("First child node must not be a parent-pointer pseudo-node"); Here's the full stack trace of interest Thread [main] (Suspended (exception IllegalStateException)) TinyTreeEventIterator.next() line: 139 EventStackIterator.next() line: 54 NamespaceMaintainer.next() line: 69 EventToStaxBridge.next() line: 220 Stax2ReaderAdapter(StreamReaderDelegate).next() line: 60 Stax2ReaderAdapter.next() line: 129 WstxEventReader(Stax2EventReaderImpl).nextEvent() line: 255 Stax2EventWriterImpl.add(XMLEventReader) line: 171 xidentity.run(List<XValue>) line: 29 xidentity(XCommand).run(List<XValue>, XEnvironment) line: 55 xidentity(XCommand).run(Shell, String, List<XValue>) line: 45 SimpleCommand.exec(Shell) line: 102 Shell.exec(Command) line: 395 Pipeline.exec(Shell) line: 112 Shell.exec(Command) line: 395 Shell.interactive() line: 311 Shell.main(String[]) line: 491 Any suggestions on what I might be doing wrong ? Thanks for any ideas. -David


Replies (4)

Please register to reply

RE: IllegalStateException using EventToStaxBridge - Added by Anonymous about 15 years ago

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

That looks like this bug https://sourceforge.net/tracker2/?func=detail&amp;aid=2550711&amp;group_id=29872&amp;atid=397617 which has been fixed in Saxon 9.1.0.6

RE: IllegalStateException using EventToStaxBr - Added by Anonymous about 15 years ago

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

Thanks this works ! Sorry for not trying 9.1.0.6 before posting this, I was on 9.1.0.5 and hadn't updated yet. Now on the reverse task. creating a XMLStreamWriter that creates XdmNode ... I have that working by creating a buffer of XMLEvent then using that as an input source for the Builder, but it would be nice to go directly. I think my only other option is a thread/pipe situation. If I knew ahead of time it would be a big document that might be a good idea. Thanks ! -David

RE: IllegalStateException using EventToStaxBr - Added by Anonymous about 15 years ago

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

>creating a XMLStreamWriter that creates XdmNode Sounds like you need a class that bridges XMLStreamWriter events to Receiver events in the same way that ReceivingContentHandler bridges SAX to Receiver. I would start with the RCH class and modify it to implement XMLStreamWriter. I've been reluctant to add support for the StAX push APIs. I really can't see why they are needed, there seems a complete overlap with SAX here. Michael Kay http://www.saxonica.com/

RE: IllegalStateException using EventToStaxBr - Added by Anonymous about 15 years ago

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

Thanks, I'll take a look at this, appreciate the ideas. FYI, for context, why both with the StAX PUSH API's when SAX works fine ? For my case there are 2 reasons 1) I am integrating with a variety of libraries and they dont all use the same API's ... ( wish list for real standardazation of streaming APIs ! ) So I need to support StAX for both push and pull, and both stax events and streams. But my main reason is 2) I'm working on implementing an efficient multi-threaded XML pipeline. I originally implemented this as text serialized XML which works but is non-ideal. After over a year of being wishy-washy and not finding anything thats a great fit, I've decided on attempting to use Stax Events in a 'pipe'. Its true I could write my own based on SAX but due to #1, I need StaX support anyway and the StaX Events seem like a reasonably perfect fit to the problem ... Now I just need to be able to wrap both ends and make sure all consumers and producers can produce Stax streams/events as well as consume them, and when not, be able to convert between the producer's API of choice and the consumer's API of choice. I'm not sure its going to really work, and I'm absolutely not sure its the "best" decision but I'm very close now ... Thanks for your ideas ! -David

    (1-4/4)

    Please register to reply