由Document对象转成String字符串

Writer sw = new StringWriter();
Source dom = new DOMSource(document);
Result result = new StreamResult(sw);
TransformerFactory.newInstance().newTransformer().transform(dom, result);
String xml = sw.toString();

你可能感兴趣的:(document)