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:

see

http://xmlsh.svn.sourceforge.net/viewvc/xmlsh/trunk/src/core/org/xmlsh/core/XMLEventOutputPort.java?revision=698&view=markup

 

 

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

dlee@calldei.com

http://www.xmlsh.org

 

From: Michael Kay [mailto:mike@saxonica.com]
Sent: Thursday, September 06, 2012 12:49 PM
To: saxon-help@lists.sourceforge.net
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
Saxonica