How to pretty print XML from Java?

I have an xml which is non-format as below. How i can make it nicely formatted xml.

Pass the books.xml in the below program , run the program and see output.

Output: Now we can see that books.xml is printed in nice format.