title: How to get all nodes from a DOM Document (Elements, Attributes etc)
body: <p>I am trying to get all nodes that are part of a document and am only able to get the element nodes, using <code>getElementByTagName("*")</code>. But this does not return the other nodes viz. attribute and other nodes.</p>
  
  <p>Is there an api available or do I have to iterate further on these elements to get there attribute nodes?</p>
  
  <p>This is what I am trying now; Need to know if there is any other way or a direct api for the same</p>
  
  <pre><code>private static List&lt;Node&gt; getAllNodes(Document doc) {
          List&lt;Node&gt; returnList = new LinkedList&lt;&gt;();
          NodeList nodes = doc.getElementsByTagName("*");
  
          for (int index = 0; index &lt; nodes.getLength(); index++) {
              returnList.add(nodes.item(index));
  
              NamedNodeMap attribList = nodes.item(index).getAttributes();
              if (attribList == null) {
                  continue;
              }
  
              for (int j = 0; j &lt; attribList.getLength(); j++) {
                  returnList.add(attribList.item(j));
              }
          }
          return returnList;
      }
  </code></pre>
  
  <p>Thanks in advance</p>