import java.io.StringWriter;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
public class FormatXml{
public static String formatXml(String xml){
String res = null;
try{
Document doc = DocumentHelper.parseText(xml);
OutputFormat format = OutputFormat.createPrettyPrint();
StringWriter writer = new StringWriter();
XMLWriter xmlWriter = new XMLWriter(writer,format);
xmlWriter.write(doc);
xmlWriter.close();
res = writer.toString().trim();
}catch(Exception e){}
return res;
}
}
网友评论