Java examples for XML:XML Attribute
Determining If an Attribute Was Supplied in a DOM Element
import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; public class Main { public static void main(String[] argv) throws Exception { // Get all the attributes of an element in a map Element element = null;//w w w . j a va2s . c om NamedNodeMap attrs = element.getAttributes(); // Get number of attributes in the element int numAttrs = attrs.getLength(); // Process each attribute for (int i = 0; i < numAttrs; i++) { Attr attr = (Attr) attrs.item(i); boolean wasSpecified = attr != null && attr.getSpecified(); } } }