我有一些代码:
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)
产生以下错误:
Caught:javax.xml.transform.TransformerException:无法转换类型为javax.xml.transform.stax.StAXSource的源
reader对象的类型为com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl
答案 0 :(得分:5)
所以我愚蠢地尝试了错误的事情。这修好了它:
System.setProperty("javax.xml.transform.TransformerFactory",
"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");