/**
* Pretty print XML Node
* @param node
* @return
* @throws XmlUtilitiesException
*/
public String xmlNodeToString( Node node ) throws XmlUtilitiesException {
StringWriter sw = new StringWriter();
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, "4");
transformer.setOutputProperty(OutputPropertiesFactory.S_KEY_LINE_SEPARATOR, "\n");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(node), new StreamResult(sw));
} catch (TransformerException te) {
throw new XmlUtilitiesException("Error transforming XML node to String", te);
}
return sw.toString().trim();
}
XmlUtilities.java 文件源码
java
阅读 33
收藏 0
点赞 0
评论 0
项目:ats-framework
作者:
评论列表
文章目录