我正在使用XMLSerializer编写xml,但我一直遇到一个不能解释的异常,你能帮忙吗?
09-25 10:46:31.733: WARN/System.err(23654): java.lang.IllegalArgumentException: </{}titleid> does not match start
09-25 10:46:31.944: WARN/System.err(23654): at org.kxml2.io.KXmlSerializer.endTag(KXmlSerializer.java:504)
以下KXmlSerializer.java
发生异常public XmlSerializer endTag(String namespace, String name)
throws IOException {
if (!pending)
depth--;
// if (namespace == null)
// namespace = "";
if ((namespace == null && elementStack[depth * 3] != null)
|| (namespace != null && !namespace
.equals(elementStack[depth * 3]))
|| !elementStack[depth * 3 + 2].equals(name))
throw new IllegalArgumentException("</{" + namespace + "}"
+ name + "> does not match start");
任何想法?
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);
}
}
答案 0 :(得分:0)
上面的例子是完全正确的,但我使用的实际代码有两个endTag相同而没有启动(startTag)第二个标签......
我的错误
感谢