在 xstream 中省略 xml 声明 [英] omitting xml declaration in xstream

查看:31
本文介绍了在 xstream 中省略 xml 声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 xstream 将内容附加到 xml 但每次运行时使用 xstream.toXml(obj,writer),它正在向内容添加 xml 声明,我们可以在 xstream 中省略 xml 声明吗?

I want to append content to xml using xstream but using xstream.toXml(obj,writer) every time I run this, it is adding xml declaration to the content, can we omit xml declaration in xstream?

推荐答案

在 XStream 团队正在解决问题的同时,您可以采取一种解决方法.覆盖 StaxDriver 中的 createStaxWriter:

In the meantime the XStream team is fixing the issue, you may do a workaround. Override the createStaxWriter in StaxDriver:

    StaxDriver driver = new StaxDriver() {
        @Override
        public StaxWriter createStaxWriter(XMLStreamWriter out) throws XMLStreamException {
            //the boolean parameter controls the production of XML declaration
            return createStaxWriter(out, false);  
        }
    };
    XStream xstream = new XStream(driver);

这篇关于在 xstream 中省略 xml 声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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