格式化XML文档

前端之家收集整理的这篇文章主要介绍了格式化XML文档前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。



/**
* 格式化XML文档,并解决中文问题
* @param filename
* @return
*/
public static void formatXMLFile(File xmlFile) {
try {
SAXReader saxReader = new SAXReader();
Document document = saxReader.read(xmlFile);
XMLWriter output = null;
/** 格式化输出,类型IE浏览一样 */
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
output = new XMLWriter(new FileWriter(xmlFile),format);

output.write(document);
output.close();
} catch (Exception e) {
logger.error("Obj2XMLFile() change to xml fail," + e.toString());
throw new CmsCommonException(CmsCommonErrCodes.CLASSCAST_ERROR);
}
}


原文链接:https://www.f2er.com/xml/298906.html

猜你在找的XML相关文章