The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > org.w3c.dom  [30 examples] > Element Attributes  [5 examples]

e536. Listing All the Attributes of a DOM Element

    // Get all the attributes of an element in a map
    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);
    
        // Get attribute name and value
        String attrName = attr.getNodeName();
        String attrValue = attr.getNodeValue();
    }

 Related Examples
e534. Getting and Setting an Attribute in a DOM Element
e535. Adding and Removing an Attribute in a DOM Element
e537. Removing All the Attributes in a DOM Element
e538. Determining If an Attribute Was Supplied in a DOM Element

See also: Adding and Removing Nodes    Elements    Getting Nodes    Text Nodes    XPath   


© 2002 Addison-Wesley.