Java tutorial
//package com.java2s; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { /** * Returns the attribute value with the given id for the Node * * @param n * @param id * @return */ public static String getAttribute(Node n, String id) { String result = null; NamedNodeMap attrMap = n.getAttributes(); if (null != attrMap) { Node attr = attrMap.getNamedItem(id); result = (attr == null) ? null : attr.getNodeValue(); } if (null != result) { result = result.trim(); } return result; } }