### Question:
XMLUtil { public static String loadAndNormalizeXML(File xmlFile) throws ParserConfigurationException, SAXException, IOException, TransformerException { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xmlFile); removeRecursively(doc); doc.normalizeDocument(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "no"); StringWriter normalizedXml = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(normalizedXml)); return normalizedXml.toString(); }  static String loadAndNormalizeXML(File xmlFile); static T loadXML(Class<T> type, File sourceFile); static T loadXML(Class<T> type, String schemaLocation, File sourceFile);  }### Answer:
@Test public void shouldRemoveComments() throws Exception { File xmlFile = createXmlFile("<!--comment a--><!--comment b--><items/>"); String xml = XMLUtil.loadAndNormalizeXML(xmlFile); assertEquals("<items/>", xml); }
@Test public void shouldCloseEmptyTags() throws Exception { File xmlFile = createXmlFile("<items></items>"); String xml = XMLUtil.loadAndNormalizeXML(xmlFile); assertEquals("<items/>", xml); }
@Test public void shouldRemoveWhiteSpaces() throws Exception { File xmlFile = createXmlFile("<items> <itemtypes/></items>"); String xml = XMLUtil.loadAndNormalizeXML(xmlFile); assertEquals("<items><itemtypes/></items>", xml); }
@Test public void shouldRemoveLineBreaks() throws Exception { File xmlFile = createXmlFile("<items>\n<itemtypes/>\n\r</items>"); String xml = XMLUtil.loadAndNormalizeXML(xmlFile); assertEquals("<items><itemtypes/></items>", xml); }