Java XML Parse File parseXml(String filePath)

Here you can find the source of parseXml(String filePath)

Description

Creates W3C DOM Document object from XML file

License

Open Source License

Parameter

Parameter Description
filePath path to xml file including file name and extension

Declaration

public static Document parseXml(String filePath) 

Method Source Code


//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;
        }
    }
}

Related

  1. parseXml(File file)
  2. parseXML(final File file)
  3. parseXml(String fileName)
  4. parseXml(String filename, boolean validating)
  5. parseXml(String filePath)
  6. parseXml(String value, boolean isFile)
  7. parseXMLFile(File f)
  8. parseXmlFile(File file)
  9. parseXmlFile(File file, boolean validating)