title: How to parse all children and grandchildren elements from a current node using xml.etree.ElementTree in python
body: <p>I am extracting all the text in xml document. I want to look for tag say <strong>description</strong> and then search through all the children and grandchildren and there could be even more elements and then extract the text.</p>
  
  <p>Here is my code but it is not able to get text inside the grandchildren tags:</p>
  
  <pre><code>for element in root.find('description'):
      print 'parent: ', element.tag, '|', element.attrib
      try:
          data.write(element.text)
          for all_tags in element.findall('./'):
              print 'child: ', all_tags.tag, '|', all_tags.attrib
              if all_tags.text:
                  data.write('\n')
                  data.write(all_tags.text)
                  if all_tags.tail:
                      data.write('\n')
                      data.write(all_tags.tail)
                      data.write('\n')
          data.write('\n')
      except TypeError:
          pass
      except UnicodeEncodeError:
          unicodestr = element.text.encode("utf-8")
          data.write(unicodestr)
  
      data.write('\n')
  </code></pre>
  
  <p>The problem is in the <code>for all_tags</code> loop.</p>
  
  <p>sample input:</p>
  
  <pre><code>&lt;description&gt;
  &lt;p num="p-0003"&gt;
  Protein kinases are involved in the signal transduction pathways linking growth factors, hormones and other cell regulation molecules to cell growth, survival and metabolism under both normal and pathological conditions. One such protein kinase, protein kinase B (also known as Akt), is a serine/threonine kinase that plays a central role in promoting the proliferation and survival of a wide range of cell types, thereby protecting cells from apoptosis (programmed cell death) (Khwaja,
  &lt;i&gt;Nature&lt;/i&gt;
  33-34 (1990)). Three members of the Akt/PKB subfamily of second-messenger regulated serine/threonine protein kinases have been identified and are termed Akt1/PKBα, Akt2/PKBβ, and Akt3/PKBγ. A number of proteins involved in cell proliferation and survival have been described as substrates of Akt in cells. Two examples of such substrates include glycogen synthase kinase-3 (GSK3) and Forkhead transcription factors (FKs). See Brazil and Hemmings,
  &lt;i&gt;Trends in Biochemical Sciences&lt;/i&gt;
  26, 675-664.
  &lt;/p&gt;
  &lt;p num="p-0004"&gt;
  A number of protein kinases and phosphatases regulate the activity of Akt; For instance, activation of Akt is mediated by phosphatidylinositol 3-kinase (PI3-K), which initiates the binding of second messenger phospholipids to the pleckstrin homology (PH) binding domain of Akt. The binding anchors Akt to plasma membrane and results in phosphorylation and activation of the enzyme. Amplifications of the catalytic subunit of PI3-K, p110α, or mutations in the PI3-K regulatory subunit, p85α, lead to activation of Akt in several types of human cancer. (Vivanco and Sawyers,
  &lt;i&gt;Nature Reviews in Cancer&lt;/i&gt;
  (2002) 2: 489-501.
  &lt;/p&gt;
  &lt;p num="p-0005"&gt;
  The tumor suppressor, PTEN, is a critical negative regulator of Akt activation by PI3-K. Myers et al.
  &lt;/p&gt;
  &lt;/description&gt;
  </code></pre>
  
  <p>In this input, the text after <code>&lt;i&gt; Nature &lt;/i&gt;</code>  is missed and replaced by text in the first line. This is I believe due to the <code>all_tags.tail</code> is getting text from the parent tag not from the children and grandchildren tags.</p>