用Java转换StAX源代码 [英] Transforming a StAX Source in Java
本文介绍了用Java转换StAX源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些代码如下:
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)
产生以下错误:
捕获:javax.xml.transform.TransformerException:无法转换类型为javax.xml.transform.stax.StAXSource的源
Caught: javax.xml.transform.TransformerException: Can't transform a Source of type javax.xml.transform.stax.StAXSource
reader对象的类型为 com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl
The reader object is of type com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl
推荐答案
所以我愚蠢地尝试了错误的事情。这修复了它:
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");
这篇关于用Java转换StAX源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文