Java tutorial
//package com.java2s; /********************************************************************************************* * * * 'XMLUtils.java', in plugin 'msi.gama.documentation', is part of the source code of the GAMA modeling and simulation * platform. (c) 2007-2014 UMI 209 UMMISCO IRD/UPMC & Partners * * Visit https://code.google.com/p/gama-platform/ for license information and developers contact. * * **********************************************************************************************/ import java.io.File; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.xml.sax.SAXException; public class Main { public static Document createDoc(final String xml) throws ParserConfigurationException, SAXException, IOException { // Creation of the DOM source final File fileXml = new File(xml); return createDoc(fileXml); } public static Document createDoc(final File XMLFile) throws ParserConfigurationException, SAXException, IOException { // Creation of the DOM source final DocumentBuilderFactory fabriqueD = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = fabriqueD.newDocumentBuilder(); final Document document = builder.parse(XMLFile); return document; } public static Document createDoc(final InputStream docFile) throws ParserConfigurationException, SAXException, IOException { final DocumentBuilderFactory fabriqueD = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = fabriqueD.newDocumentBuilder(); final Document document = builder.parse(docFile); return document; } }