The NamedNodeMap Interface

If for some reason you want all the attributes of an element or you don't know their names, you can use the getAttributes() method to retrieve a NamedNodeMap inherited from the Node.[3] The NamedNodeMap interface, summarized in Example 11.5, has methods to get and set the various named nodes as well as to iterate through the nodes as a list. Here it's used for attributes, but soon you'll see it used for notations and entities as well.

[3] Why getAttributes() is in Node instead of Element I have no idea. Elements are the only kind of node that can have attributes. For all other types of node, getAttributes() returns null.

Example 11.5. The NamedNodeMap Interface
 package org.w3c.dom; public interface NamedNodeMap { // ...

Get Processing XML with Java™: A Guide to SAX, DOM, JDOM, JAXP, and TrAX 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.