Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transforming a StAX Source in Java

I have some code like:

XMLInputFactory xif = XMLInputFactory.newInstance()
TransformerFactory tf = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl", null)

Transformer t = tf.newTransformer()
DOMResult result = new DOMResult()
t.transform(new StAXSource(reader), result)

Which produces the following error:

Caught: javax.xml.transform.TransformerException: Can't transform a Source of type javax.xml.transform.stax.StAXSource

The reader object is of type com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl

like image 551
arlogb Avatar asked May 29 '13 12:05

arlogb


1 Answers

So I was stupidly trying the wrong thing. This fixed it:

System.setProperty("javax.xml.transform.TransformerFactory",
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
like image 115
arlogb Avatar answered Oct 09 '22 12:10

arlogb