Name

attributes: NamedNodeMap

Synopsis

Has meaning only for Element objects. It provides access to a list of Attr objects in a NamedNodeMap. For all other object types, it returns null.

Java binding

public NamedNodeMap getAttributes( );

Java example

// List the attributes of an Element node
NamedNodeMap nnm = doc.getDocumentElement( ).getAttributes( );
     
if (nnm != null) {
     
    for (int i = 0; i < nnm.getLength( ); i++) {
        // print the attribute and value
        System.out.println(nnm.item(i).getNodeName( ) + " = \"" +
                           nnm.item(i).getNodeValue( ) + "\"");
    }
}

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.