`

对xml文件格式化(主要用到了dom4j)

XML 
阅读更多
/**
     * @des  对xml字符串进行格式化输出
     * @param s xml文件的字符串
     * @return
     */
    public static String formatXmlString(String s)
    {
        SAXReader saxreader = new SAXReader();
        StringReader stringreader = new StringReader(s);
        org.dom4j.Document document = null;
        try
        {
            document = saxreader.read(stringreader);
        }
        catch(DocumentException documentexception)
        {
            ExceptionUtil.throwActualException(documentexception);
        }
        OutputFormat outputformat = OutputFormat.createPrettyPrint();
        outputformat.setSuppressDeclaration(true);
        StringWriter stringwriter = new StringWriter();
        XMLWriter xmlwriter = new XMLWriter(stringwriter, outputformat);
        try
        {
            xmlwriter.write(document);
        }
        catch(IOException ioexception)
        {
            ExceptionUtil.throwActualException(ioexception);
        }
        return stringwriter.toString();
    }
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics