Java–Pretty print xml string

To print a formatted xml string in Java, first convert the raw string into a Document object, then use Transformer class to format the output like so:

pretty

Now simply call this method to print the formatted xml string for e.g.,

main

output