XStream - xml版本的标签创建 [英] XStream - Tag Creation for xml version

查看:178
本文介绍了XStream - xml版本的标签创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读Xstream教程

I was going through the Xstream tutorials

http://x-stream.github.io/annotations-tutorial.html

如何将处理指令添加到xml回复

How can i add the processing instruction to the xml responses

<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n

Ex:Xstream将响应视为

Ex: Xstream gives the response as

<message><type>15</type></message>

但我希望该指令也是回复的一部分..

But i would want the instruction also part of the response..

我有什么方法可以得到它..

Is there any way i could get it ..

现在正在使用此标签为字符串响应添加前缀,我觉得这不是最佳方法。

For now am prefixing the string response with this tag which i feel is not the best approach.

问候

推荐答案

如果您正在谈论添加XML 标题到输出,这是如何做到的:

If you are talking about adding the XML header to the output, here's how to do that:

XStream xstream = new XStream();
Writer writer = new StringWriter();
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
xstream.toXML(object, writer);
System.out.println(writer.toString());

这篇关于XStream - xml版本的标签创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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