private static String formatXml(Context context, String src) throws TransformerException,
ParserConfigurationException, IOException, SAXException {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(src)));
AppSetting setting = new AppSetting(context);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", setting.getTab().length() + "");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
//initialize StreamResult with File object to save to file
StreamResult result = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
return result.getWriter().toString();
}
FormatFactory.java 文件源码
java
阅读 29
收藏 0
点赞 0
评论 0
项目:javaide
作者:
评论列表
文章目录