Thanks for the pointer. I did spot your post from several years ago mentioning this, and wondered if there was some code that could be useful.

The main difficulties in doing this will be (a) finding a way to do it while still allowing Saxon to run under JDK 1.5, and (b) testing.

Michael Kay

On 06/09/2012 19:19, David Lee wrote:

staxutils has come code you can use to do this.

For xmlsh if I hafe a XMLEventWriter and want to turn it into a Destination I use this:




public synchronized Destination asDestination(SerializeOpts opts) throws CoreException



           DefaultHandler handler;

           try {

                handler = new ContentHandlerToXMLEventWriter( asXMLEventWriter(opts) );

           } catch (XMLStreamException e) {

                throw new CoreException(e);


           Destination dest = new SAXDestination( handler );

           return dest ;








David A. Lee


From: Michael Kay []
Sent: Thursday, September 06, 2012 12:49 PM
Subject: Re: [saxon] XMLEventWriter Result supported?


No, StAXResult isn't currently recognized. I'm not sure why: Saxon goes to great lengths to recognize StAXSource, despite the complications of needing to work on both JDK 1.5 and JDK 1.6. I think it's simply because no-one has asked for it. Plus the fact that when people want a push API, they generally use SAX, despite the fact that in many ways XMLStreamWriter is a nicer design. (I'm not sure about XMLEventWriter, though).

Does Saxon-HE not support StAX?? Isn't that an API violation? According to the StAXResult Javadoc:

StAXResult can be used in all cases that accept a Result, e.g. Transformer, Validator which accept Result as input.


The JDK 1.6 specification has no right to impose obligations or make assertions regarding non-JDK code that was written before the API was published. It's speaking only for its own implementations of Transformer and Validator.

Michael Kay

Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 

saxon-help mailing list archived at