public static String format(String xmlStr, OutputFormat formater) {
        if (CommUtil.isBlank(xmlStr))
            return xmlStr;


        SAXReader reader = new SAXReader();
        StringReader sr = new StringReader(xmlStr);

        Document doc;
        XMLWriter writer = null;
        StringWriter sw = new StringWriter();
        try {
            doc = reader.read(sr);
            writer = new XMLWriter(sw, formater);
            writer.write(doc);
            return sw.toString();
        } catch (DocumentException e) {
            log.error("{}", e.getMessage(), e);
        } catch (IOException e) {
            log.error("{}", e.getMessage(), e);
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException ignored) {
                }
            }

        }

        return xmlStr;
    }
public static String format ( String xmlStr , OutputFormat formater ) { if ( CommUtil . isBlank ( xmlStr ) ) return xmlStr ; SAXReader reader = new SAXReader ( ) ; StringReader sr = new StringReader ( xmlStr ) ; Document doc ; XMLWriter writer = null ; StringWriter sw = new StringWriter ( ) ; try { doc = reader . read ( sr ) ; writer = new XMLWriter ( sw , formater ) ; writer . write ( doc ) ; return sw . toString ( ) ; } catch ( DocumentException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } catch ( IOException e ) { log . error ( "{}" , e . getMessage ( ) , e ) ; } finally { if ( writer != null ) { try { writer . close ( ) ; } catch ( IOException ignored ) { } } } return xmlStr ; }
Format xml

@param xmlStr   xml String
@param formater {@link OutputFormat}
@return format String