title: xml parse without the recursive search python
body: <p>This is driving me mental, and I've probably been hacking away at it for to long so would appreciate some help to prevent lose of/restore my sanity! The food based xml is only an example of what I wish to achieve.</p>
  
  <p>I have the following file which I am trying to put into a graph, so wheat and fruit are parents with a depth of 0. Indian is a child of wheat with a depth of 1 and so on and so on. </p>
  
  <p>Each of the layers has some keywords. So what I want to get out is </p>
  
  <pre><code>layer, depth, parent, keywords
  wheat, 1, ROOT, [bread, pita, narn, loaf]  
  indian, 2, wheat [chapati]
  mumbai, 3, indian, puri 
  fruit, 1,ROOT, [apple, orange, pear, lemon]
  </code></pre>
  
  <p>This is a sample file  -</p>
  
  <pre><code>&lt;keywords&gt;
      &lt;layer id="wheat"&gt;
          &lt;layer id="indian"&gt;
              &lt;keyword&gt;chapati&lt;/keyword&gt;
              &lt;layer id="mumbai"&gt;
                  &lt;keyword&gt;puri&lt;/keyword&gt;
              &lt;/layer&gt;
          &lt;/layer&gt;
          &lt;keyword&gt;bread&lt;/keyword&gt;
          &lt;keyword&gt;pita&lt;/keyword&gt;
          &lt;keyword&gt;narn&lt;/keyword&gt;
          &lt;keyword&gt;loaf&lt;/keyword&gt;
      &lt;/layer&gt;
      &lt;layer id="fruit"&gt;
          &lt;keyword&gt;apple&lt;/keyword&gt;
          &lt;keyword&gt;orange&lt;/keyword&gt;
          &lt;keyword&gt;pear&lt;/keyword&gt;
          &lt;keyword&gt;lemon&lt;/keyword&gt;
      &lt;/layer&gt;
  
  &lt;/keywords&gt;
  </code></pre>
  
  <p>So this isnt a graph question, I can do that bit thats easy. What im struggling with is parsing the XML.</p>
  
  <p>If I do a </p>
  
  <pre><code>xmldoc = minidom.parse(self.filename)
  
  layers = xmldoc.getElementsByTagName('layer')
  </code></pre>
  
  <p>layers only returns all of the layer elements, which is to much and has not concept of depth/ hierachy as far as I can understand as it does a recursive search.</p>
  
  <p>The following post is good, but doesnt provide the concepts I require. <a href="https://stackoverflow.com/questions/1596829/xml-parsing-with-python-and-minidom">XML Parsing with Python and minidom</a>. Can anyone help with how I might go about this? I can post my code but its so hacked together/fundementally broken I don't think it would be use to man nor beast!</p>
  
  <p>Cheers</p>
  
  <p>Dave</p>