You could read it into a DOM, then delete any nodes that are text nodes that contain only whitespace. Or you could write an XSLT template that copies all nodes except text nodes that contain only whitespace.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: how to remove indentation in a xml using java api