Java XML Document from File readXml(String path)

Here you can find the source of readXml(String path)

Description

read Xml

License

Apache License

Declaration

private static Document readXml(String path) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

public class Main {
    private static Document readXml(String path) throws IOException {
        File in = new File(path);
        if (!in.exists())
            return null;
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        try {//w  ww . jav a2  s  .co  m
            DocumentBuilder db = dbf.newDocumentBuilder();
            return db.parse(in);
        } catch (IOException ex) {
            throw ex;
        } catch (Throwable err) {
            throw ((IOException) new IOException("Failed to load XML " + in.getPath()).initCause(err));
        }
    }
}

Related

  1. readXml(File file)
  2. readXML(File file)
  3. readXML(File file)
  4. readXML(File file)
  5. readXML(File xml)
  6. readXML(String path)
  7. readXMLFile(File file)
  8. readXMLFile(String filename)
  9. readXmlFile(String fileName)