title: Java XML: get nested element
body: <p>I'm programming a simple Java game and I wanted to save to player data to an XML encoded save file. Currently I'm discovering the Java XML DOM API and I have a short question.</p>
  
  <p>Suppose I have the following XML file (doesn't make sense I know, but it is just an example)</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;savedGame&gt;
      &lt;name&gt;&lt;/name&gt;
      &lt;player&gt;
          &lt;name&gt;YOU&lt;/name&gt;
          &lt;map&gt;
                          &lt;health&gt;2000&lt;/health&gt;
              &lt;name&gt;map_test.map&lt;/name&gt;
              &lt;position&gt;
                  &lt;x&gt;0&lt;/x&gt;
                  &lt;y&gt;0&lt;/y&gt;
              &lt;/position&gt;
          &lt;/map&gt;
          &lt;stats&gt;
              &lt;health&gt;1000&lt;/health&gt;
              &lt;xp&gt;
                  &lt;melee&gt;&lt;/melee&gt;
                  &lt;magic&gt;&lt;/magic&gt;
                  &lt;ranged&gt;&lt;/ranged&gt;
                  &lt;agility&gt;&lt;/agility&gt;
              &lt;/xp&gt;
          &lt;/stats&gt;
          &lt;items&gt;
              &lt;item id="0"&gt;
                  &lt;amount&gt;&lt;/amount&gt;
              &lt;/item&gt;
          &lt;/items&gt;
      &lt;/player&gt;
  &lt;/savedGame&gt;
  </code></pre>
  
  <p>Now I want to get the players health level (note that there is an other health element in the map section). This can be done with the following code:</p>
  
  <pre><code>String hp = ((Element) ((Element) savedGameDocument.getElementsByTagName("player").item(0)).getElementsByTagName("stats").item(0)).getElementsByTagName("health").item(0).getTextContent()
  </code></pre>
  
  <p>It works, yes. But it looks very nasty to me. Is this the usual way for getting those nested elements? And why isn't there an ElementList class? Now I have to cast every Node.</p>
  
  <p>Thanks in advance,
  Jori.</p>