Java tutorial
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { public static String getNodeAttribute(Node node, String name) { return getNamedItemNodeValue(node.getAttributes(), name, null); } public static String getNodeAttribute(Node node, String name, String def) { return getNamedItemNodeValue(node.getAttributes(), name, def); } static String getNamedItemNodeValue(NamedNodeMap attributes, String name, String defvalue) { Node namenode = attributes.getNamedItem(name); if (namenode == null) { return defvalue; } if (namenode.getNodeValue() == null) { return defvalue; } return namenode.getNodeValue(); } }