Here you can find the source of readXmlFile(String fileName)
Parameter | Description |
---|---|
fileName | full name of a xml file |
Parameter | Description |
---|---|
IOException | an exception |
public static Document readXmlFile(String fileName) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; public class Main { /**/*from w w w.j a va 2 s . c o m*/ * parse xmlFile in a Document * * @param fileName * full name of a xml file * @return a Dom Document * @throws IOException */ public static Document readXmlFile(String fileName) throws IOException { Document doc = null; try { File xmlFile = new File(fileName); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = factory.newDocumentBuilder(); doc = docBuilder.parse(xmlFile); } catch (Exception e) { System.out.println("Error on parsing XML file : " + fileName); e.printStackTrace(); throw new IOException("Error on parsing XML file : " + fileName); } return doc; } }