@Override
    public String format(String xml) {
        String formattedString;
        if (xml == null || xml.trim().length() == 0) {
            throw new FormatException("XML empty.");
        }
        try {
            Source xmlInput = new StreamSource(new StringReader(xml));
            StreamResult xmlOutput = new StreamResult(new StringWriter());
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
                    String.valueOf(XML_INDENT));
            transformer.transform(xmlInput, xmlOutput);
            formattedString = xmlOutput.getWriter().toString().replaceFirst(">", ">"
                    + SystemCompat.lineSeparator);
        } catch (Exception e) {
            throw new FormatException("Parse XML error. XML string:" + xml, e);
        }
        return formattedString;
    }
Simply format the XML with a indent of {@value XML_INDENT}.
<br>TODO: Make indent size and enable/disable state configurable.
android/android_framework/base/src/main/java/com/elvishew/xlog/formatter/message/xml/DefaultXmlFormatter.java