parse File and return XML Document - Java XML

Java examples for XML:DOM Document

Description

parse File and return XML Document

Demo Code


//package com.java2s;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

import java.io.File;

public class Main {
    public static Document parseDoc(File f) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory
                .newInstance();// w  w  w. j  av  a  2  s  . co  m
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(f);
    }
}

Related Tutorials