title: generic foreach iteration of NamedNodeMap
body: <p>In Java, looking at the <a href="http://download.oracle.com/javase/6/docs/api/org/w3c/dom/NamedNodeMap.html" rel="noreferrer">NamedNodeMap</a> interface, how do you iterate it with generics?  It seems to use Node rather than String, but I'm not so sure how to use Node objects...</p>
  
  <pre><code>NamedNodeMap namedNodeMap = doc.getAttributes();
  Map&lt;String, String&gt; stringMap = (Map&lt;String, String&gt;) namedNodeMap;
  for (Map.Entry&lt;String, String&gt; entry : stringMap.entrySet()) {
    //key,value stuff here
  }
  </code></pre>
  
  <p>Yes, I can see how to iterate without using generics and with a regular for loop, but I'd like to use the above ?idiom? for maps.  Of course, the problem would appear to be that, despite the name, NamedNodeMap doesn't actually implement the Map interface!  :(</p>
  
  <p>Guess you just gotta bite the bullet here and do something like:</p>
  
  <pre><code>/*
   * Iterates through the node attribute map, else we need to specify specific 
   * attribute values to pull and they could be of an unknown type
   */
  private void iterate(NamedNodeMap attributesList) {
      for (int j = 0; j &lt; attributesList.getLength(); j++) {
          System.out.println("Attribute: "
                  + attributesList.item(j).getNodeName() + " = "
                  + attributesList.item(j).getNodeValue());
      }
  }
  </code></pre>
  
  <p>there's nothing nicer?      </p>