Open Dom Document from file path - Java XML

Java examples for XML:DOM

Description

Open Dom Document from file path

Demo Code

// This program is free software; you can redistribute it and/or modify it
//package com.java2s;
import org.w3c.dom.*;
import java.io.*;
import javax.xml.parsers.*;

public class Main {

    public static Document OpenDom(String sfilepath) {
        Document newdoc = null;/*from w w  w  .  j ava 2 s  .  c  o  m*/
        try {
            newdoc = getDocumentBuilder().parse(new File(sfilepath));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return newdoc;
    }

    static DocumentBuilder getDocumentBuilder() {
        DocumentBuilder documentBuilder = null;
        try {
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
                    .newInstance();
            documentBuilder = documentBuilderFactory.newDocumentBuilder();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return documentBuilder;
    }
}

Related Tutorials