XStream - Tag Creation for xml version

廉价感情. 提交于 2019-12-12 00:46:54

问题


I was going through the Xstream tutorials

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

How can i add the processing instruction to the xml responses

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

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.

Regards


回答1:


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());


来源:https://stackoverflow.com/questions/39020597/xstream-tag-creation-for-xml-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!