我有一些类似的代码:
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
阅读器对象的类型是 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 源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!