У меня была такая же проблема, и у меня был большой успех с JTidy ( http://jtidy.sourceforge.net/index.html )
Пример:
Tidy t = new Tidy();
t.setIndentContent(true);
Document d = t.parseDOM(
new ByteArrayInputStream("HTML goes here", null);
OutputStream out = new ByteArrayOutputStream();
t.pprint(d, out);
String html = out.toString();