Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.NodeList; public class Main { public static String getAttribute(Element elem, String attr, String def) { NodeList nlist = elem.getElementsByTagName("attribute"); String value = null; for (int i = 0; i < nlist.getLength(); i++) { Element node = (Element) nlist.item(i); if (attr.equals(node.getAttribute("name"))) { value = node.getTextContent(); break; } } if (value == null) { value = def; } return value; } }