Java tutorial
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { public static String getId(Node node) { try { NamedNodeMap nnm = node.getAttributes(); Node attrib = nnm.getNamedItem("Id"); Object ID; if (attrib.hasChildNodes()) { ID = attrib.getChildNodes().item(0).getNodeValue(); } else { ID = attrib.getNodeValue(); } return ID.toString(); } catch (Exception ex) { return ""; } } }