Java tutorial
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * Gets an attribute value or an empty string if not found * * @param node Node with the attribute * @param attrName Name of the attribute * @return Value of the attribute or empty string if not found */ public static String getAttribute(Node node, String attrName) { NamedNodeMap attributes = node.getAttributes(); if (attributes == null) return ""; Node attr = attributes.getNamedItem(attrName); if (attr != null) { return attr.getNodeValue(); } else { return ""; } } }