title: How to produce xml structure up to certain xml node ussing Python?
body: <p>I am new for this stuff. Because of my original xml is about 8GB it is hard to explore all parents, grandparents, grandgrandparents, etc. for the interested child in the original xml manually. I am trying to look through all the nodes until interested child is found. So I want to create "skeleton" structure of xml upto the interested child of country_data.xml from here <a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow">https://docs.python.org/2/library/xml.etree.elementtree.html</a>. Sorry for the code: </p>
  
  <pre><code>def LookThrougStructure(parent, xpath_str, stop_flag):
      out_str.write('Parent tag: %s\n' % (parent.tag))
      for child in parent:
          if child.tag == my_tag:
              out_str.write('Child tag: %s\n' % (child.tag))
              #my_node_is_found_flag = 1
              break
          LookThrougStructure(child, child.tag, 0)
      return  
  import xml.etree.ElementTree as ET
  tree = ET.parse('country_data.xml')
  root = tree.getroot()
  my_tag = 'neighbor'
  out_str = open('xml_structure.txt', 'w')
  LookThrougStructure(root, root.tag, my_tag)
  out_str.close()
  </code></pre>
  
  <p>It works wrong and yelds all node tags:</p>
  
  <blockquote>
    <p>Parent tag: data Parent tag: country Parent tag: rank Parent tag: year
    Parent tag: gdppc Child tag: neighbor Parent tag: country Parent tag:
    rank Parent tag: year Parent tag: gdppc Child tag: neighbor Parent
    tag: country Parent tag: rank Parent tag: year Parent tag: gdppc Child
    tag: neighbor</p>
  </blockquote>
  
  <p>But I want something like that (my interested child is"neighbor"):</p>
  
  <ul>
  <li>data
  
  <ul>
  <li>country
  
  <ul>
  <li>neighbor</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>Or that: /data/country/neighbor.
  What is wrong?</p>