在 Java 中转换 StAX 源 [英] Transforming a StAX Source in Java

查看:48
本文介绍了在 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

阅读器对象的类型是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆