get XML Document from File - Java XML

Java examples for XML:DOM Document

Description

get XML Document from File

Demo Code


//package com.java2s;

import javax.xml.parsers.*;
import org.w3c.dom.*;

public class Main {
    public static Document getDocument(String path_to_file) {
        Document d = null;/*ww w .ja v a  2  s.c o m*/
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory
                    .newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();
            d = db.parse(path_to_file);
        } catch (Exception ex) {
            d = null;
        }
        return d;
    }
}

Related Tutorials