Mega Code Archive

 
Categories / Java / XML
 

Get element by tag from Document

import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Util{   /**    * Renvoie le premier élément avec le tag correspondant    *     * @param d    * @param tag    * @return    */   public static Element getTag(Document d, String tag) {     NodeList list = d.getElementsByTagName(tag);     if (list.getLength() > 0)       return (Element) list.item(0);     else       return null;   } }