title: beautifulsoup findall
body: <p>I have some xml:</p>
  
  <pre><code>&lt;article&gt;
  &lt;uselesstag&gt;&lt;/uslesstag&gt;
  &lt;topic&gt;oil, gas&lt;/topic&gt;
  &lt;body&gt;body text&lt;/body&gt;
  &lt;/article&gt;
  
  &lt;article&gt;
  &lt;uselesstag&gt;&lt;/uslesstag&gt;
  &lt;topic&gt;food&lt;/topic&gt;
  &lt;body&gt;body text&lt;/body&gt;
  &lt;/article&gt;
  
  &lt;article&gt;
  &lt;uselesstag&gt;&lt;/uslesstag&gt;
  &lt;topic&gt;cars&lt;/topic&gt;
  &lt;body&gt;body text&lt;/body&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p>There are many, many useless tags.
  I want to use beautifulsoup to collect all of the text in the body tags and their associated topic text to create some new xml.</p>
  
  <p>I am new to python, but I suspect that some form of</p>
  
  <pre><code>import arff
  from xml.etree import ElementTree
  import re
  from StringIO import StringIO
  
  import BeautifulSoup
  from BeautifulSoup import BeautifulSoup
  
  totstring=""
  
  with open('reut2-000.sgm', 'r') as inF:
      for line in inF:
          string=re.sub("[^0-9a-zA-Z&lt;&gt;/\s=!-\"\"]+","", line)
      totstring+=string
  
  
  soup = BeautifulSoup(totstring)
  
  body = soup.find("body")
  
  
  
  for anchor in soup.findAll('body'):
      #Stick body and its topics in an associated array?
  
  
  
  
  file.close
  </code></pre>
  
  <p>will work.</p>
  
  <p>1) How do I do it?
  2) Should I add a root node to the XML? otherwise it's not proper XML is it?</p>
  
  <p>Thanks very much</p>
  
  <p>Edit: </p>
  
  <p>What i want to end up with is:</p>
  
  <pre><code>&lt;article&gt;
  &lt;topic&gt;oil, gas&lt;/topic&gt;
  &lt;body&gt;body text&lt;/body&gt;
  &lt;/article&gt;
  
  &lt;article&gt;
  &lt;topic&gt;food&lt;/topic&gt;
  &lt;body&gt;body text&lt;/body&gt;
  &lt;/article&gt;
  
  &lt;article&gt;
  &lt;topic&gt;cars&lt;/topic&gt;
  &lt;body&gt;body text&lt;/body&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p>There are many, many useless tags.</p>