Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * Gets the attribute as a string. * @param key the name of the attribute. * @param map the named node map with the attribute key/value pairs. * @return the attribute value or an empty string if it does not exist. */ public static String getAttribute(String key, NamedNodeMap map) { Node attr = map.getNamedItem(key); return attr != null ? attr.getTextContent() : ""; } }