Java tutorial
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * Retrieves the value for a xml Node attribute or a default if not found. * * @param node The Node to fetch the value from. * @param name The attribute name. * @param defaultValue The default value to return if not found. * @return and attribute value or a default if not found. */ public static String getNodeAttributeOrDefault(Node node, String name, String defaultValue) { NamedNodeMap attributes = node.getAttributes(); Node valueNode = attributes.getNamedItem(name); String value = defaultValue; if (valueNode != null) value = valueNode.getNodeValue(); return value; } }