Java XML Format prettyPrintXML(String xml)

Here you can find the source of prettyPrintXML(String xml)

Description

pretty Print XML

License

Apache License

Declaration

public static String prettyPrintXML(String xml) throws TransformerException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;

import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import java.io.StringReader;
import java.io.StringWriter;

public class Main {
    public static String prettyPrintXML(String xml) throws TransformerException {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        StreamResult result = new StreamResult(new StringWriter());
        StreamSource source = new StreamSource(new StringReader(xml));
        transformer.transform(source, result);
        return result.getWriter().toString();
    }//w w w .j ava  2 s. com
}

Related

  1. prettyPrint(String header, String xml)
  2. prettyPrintToString(String xml)
  3. prettyPrintXml(SOAPMessage message)
  4. prettyPrintXml(String input)
  5. prettyPrintXml(String input)
  6. prettyXml(final String xml)
  7. prettyXml(String xml)
  8. prettyXml(String xml)
  9. prettyXml(String xml)