Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; public class Main { public static Document getNormalizedDocumentFromFile(File file) throws SAXException, IOException, ParserConfigurationException { Document doc = getDocumentFromFile(file); doc.getDocumentElement().normalize(); return doc; } public static Document getDocumentFromFile(File file) throws SAXException, IOException, ParserConfigurationException { return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(file); } }