本文介绍了我们怎样才能创造一个机器人XMLWriter的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们怎样才能传递给解析器的时候会写的XML指定的OutputStream创建XMLWriter的?作家。是否有任何的android直接类达致这?先谢谢了。
How can we create a XMLWriter?The writer when passed to the parser will write the XML to the specified outputStream. Is there any direct class in android to acheive this? Thanks in advance.
推荐答案
使用.
示例
private String writeXml(List<Message> messages){
XmlSerializer serializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
try {
serializer.setOutput(writer);
serializer.startDocument("UTF-8", true);
serializer.startTag("", "messages");
serializer.attribute("", "number", String.valueOf(messages.size()));
for (Message msg: messages){
serializer.startTag("", "message");
serializer.attribute("", "date", msg.getDate());
serializer.startTag("", "title");
serializer.text(msg.getTitle());
serializer.endTag("", "title");
serializer.startTag("", "url");
serializer.text(msg.getLink().toExternalForm());
serializer.endTag("", "url");
serializer.startTag("", "body");
serializer.text(msg.getDescription());
serializer.endTag("", "body");
serializer.endTag("", "message");
}
serializer.endTag("", "messages");
serializer.endDocument();
return writer.toString();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
这篇关于我们怎样才能创造一个机器人XMLWriter的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!