加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

用Java转换StAX源代码

发布时间:2020-12-15 00:54:54 所属栏目:Java 来源:网络整理
导读:我有一些代码: XMLInputFactory xif = XMLInputFactory.newInstance()TransformerFactory tf = TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl",null)Transformer t = tf.newTransformer()DOMResult result = new DOM
我有一些代码:
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: Can’t transform a Source of type javax.xml.transform.stax.StAXSource

reader对象的类型为com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl

解决方法

所以我愚蠢地尝试了错误的事情.这解决了它:
System.setProperty("javax.xml.transform.TransformerFactory","com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读