This prints my xml document on the console with pretty print.
//writing output to a file
Document writeDocument = new Document(document);
//Formatting the file
Serializer serializer = new Serializer(System.out, "UTF-8");
serializer.setIndent(4);
serializer.write(writeDocument);
I need to return the same xml document, so that I can display it in browser.
I had the exact same requirement in one of my apps. You can do this by taking the serialized XOM document, wrapping it in code tags, and escaping the angle brackets. The example code below shows one way to do this: