Java tutorial
//package com.java2s; import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.NodeList; public class Main { private static final Logger logger = LoggerFactory.getLogger("com.cffreedom.utils.XmlUtils"); public static NodeList getDomNodes(String file, String xmlTag) { NodeList nodes = null; try { File xml = new File(file); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xml); doc.getDocumentElement().normalize(); nodes = doc.getElementsByTagName(xmlTag); } catch (Exception e) { e.printStackTrace(); nodes = null; } logger.trace("Returning {} nodes", nodes.getLength()); return nodes; } }