private String Doc2XmlString(Document mydoc) {
String ret = null;
try {
DOMSource source = new DOMSource(mydoc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
coscon.x.xml.transform.Transformer
transformer = coscon.x.xml.transform.TransformerFactory.newInstance().newTransformer();
transformer.transform(source, result);
ret=writer.getBuffer().toString();
}
catch (Exception e) {
e.printStackTrace();
}
return ret;
}
Document 转 String
最新推荐文章于 2022-05-12 12:56:48 发布
本文介绍了一种将Document对象转换为XML字符串的方法。通过使用DOM Source、Stream Result及Transformer进行转换,可以有效地将内存中的Document对象序列化为XML字符串形式。
871

被折叠的 条评论
为什么被折叠?



