title: Traversing a DOM tree to get (name,value) pairs of attributes and leaf nodes
body: <p>I want to traverse through an XML file in DOM for the purpose of retrieving as (name,value) pairs all:</p>
  
  <ol>
  <li>Attribute names and values;</li>
  <li>All leaf node names and their text content;</li>
  </ol>
  
  <p>So given the following XML file as an example:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;title text="title1"&gt;
      &lt;comment id="comment1"&gt;
          &lt;data&gt; abcd &lt;/data&gt;
          &lt;data&gt; efgh &lt;/data&gt;
      &lt;/comment&gt;
      &lt;comment id="comment2"&gt;
          &lt;data&gt; ijkl &lt;/data&gt;
          &lt;data&gt; mnop &lt;/data&gt;
          &lt;data&gt; qrst &lt;/data&gt;
      &lt;/comment&gt;
  &lt;/title&gt;
  </code></pre>
  
  <p>What I want as name value pairs are:</p>
  
  <pre><code>text=title1
  id=comment1
  data=abcd
  data=efgh
  id=commment2
  data=ijkl
  data=mnop
  data=qrst
  </code></pre>