Java examples for XML:DOM
get DOM Root from XML File
//package com.java2s; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; public class Main { public static void main(String[] argv) throws Exception { String filePathName = "java2s.com"; System.out.println(getRoot(filePathName)); }/*from w ww .j av a 2s .c o m*/ public static Document getRoot(String filePathName) throws Exception { Document doc = null; DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); doc = builder.parse(filePathName); doc.normalize(); return doc; } }