Here you can find the source of parseXml(String filePath)
Parameter | Description |
---|---|
filePath | path to xml file including file name and extension |
public static Document parseXml(String filePath)
//package com.java2s; //License from project: Open Source License import java.io.IOException; 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 { /**/*from w ww.j a v a 2 s .c o m*/ * Creates W3C DOM Document object from XML file * @param filePath path to xml file including file name and extension */ public static Document parseXml(String filePath) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(filePath); doc.getDocumentElement().normalize(); return doc; } catch (ParserConfigurationException pce) { pce.printStackTrace(); return null; } catch (SAXException se) { se.printStackTrace(); return null; } catch (IOException ioe) { ioe.printStackTrace(); return null; } } }