title: Parsing XML file with DOM (Java)
body: <p>I want to parse the following url: <a href="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=nucleotide&amp;id=224589801" rel="nofollow">http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=nucleotide&amp;id=224589801</a></p>
  
  <p>As a result I came up with the following method: </p>
  
  <pre><code>public void parseXml2(String URL) {
      DOMParser parser = new DOMParser();
  
      try {
          parser.parse(new InputSource(new URL(URL).openStream()));
          Document doc = parser.getDocument();
  
          NodeList nodeList = doc.getElementsByTagName("Item");
          for (int i = 0; i &lt; nodeList.getLength(); i++) {
              Node n = nodeList.item(i);
              Node actualNode = n.getFirstChild();
              if (actualNode != null) {
                  System.out.println(actualNode.getNodeValue());
              }
          }
  
      } catch (SAXException ex) {
          Logger.getLogger(TaxMapperXml.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IOException ex) {
          Logger.getLogger(TaxMapperXml.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  </code></pre>
  
  <p>With this method I can take the values of the Item nodes but I can't take any of their attributes. I tried experimenting with getAttribute() with NamedNodeMap but still to no avail. </p>
  
  <ol>
  <li><p>Why do I have to do <code>n.getFirstChild().getNodeValue();</code> to get the actual value? <code>n.getNodeValue()</code> returns just null? Isn't this counter-intuitive - obviously in my case node's doesn't have subnodes?</p></li>
  <li><p>Is there some more robust and widely accepted way of parsing XML files using DOM? My files aren't gonna be big 15-20 lines at most, so SAX isn't necessary (or is it?)</p></li>
  </ol>