Here you can find the source of getRootFromPom(File pomFile)
public static Element getRootFromPom(File pomFile) throws Exception
//package com.java2s; //License from project: LGPL import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { public static Element getRootFromPom(File pomFile) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance();/*from w w w.ja v a 2s . c om*/ factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(pomFile); Element root = document.getDocumentElement(); return root; } }