title: How to get value from XML Tag in Python?
body: <p>I have XML file as below. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;searching&gt;
     &lt;query&gt;query01&lt;/query&gt;
     &lt;document id="0"&gt;
        &lt;title&gt;lord of the rings.&lt;/title&gt;
      &lt;snippet&gt;
        this is a snippet of a document.
      &lt;/snippet&gt;
        &lt;url&gt;http://www.google.com/&lt;/url&gt;
     &lt;/document&gt;
     &lt;document id="1"&gt;
        &lt;title&gt;harry potter.&lt;/title&gt;
      &lt;snippet&gt;
              this is a snippet of a document.
      &lt;/snippet&gt;
        &lt;url&gt;http://www.google.com/&lt;/url&gt;
     &lt;/document&gt;
     ........ #and other documents .....
  
    &lt;group id="0" size="298" score="145"&gt;
        &lt;title&gt;
           &lt;phrase&gt;GROUP A&lt;/phrase&gt;
        &lt;/title&gt;
        &lt;document refid="0"/&gt;
        &lt;document refid="1"/&gt;
        &lt;document refid="84"/&gt;
     &lt;/group&gt;
    &lt;group id="0" size="298" score="55"&gt;
        &lt;title&gt;
           &lt;phrase&gt;GROUP B&lt;/phrase&gt;
        &lt;/title&gt;
        &lt;document refid="2"/&gt;
        &lt;document refid="13"/&gt;
        &lt;document refid="3"/&gt;
     &lt;/group&gt;
     &lt;/&lt;searching&gt;&gt;
  </code></pre>
  
  <p>I want to get the group name above and what are the document id (and its title) in each group. My idea is store document id and document title into dictionary as:</p>
  
  <pre><code>import codecs
  documentID = {}    
  group = {}
  
  myfile = codecs.open("file.xml", mode = 'r', encoding = "utf8")
  for line in myfile:
      line = line.strip()
      #get id from tags
      #get title from tag
      #store in documentID 
  
  
      #get group name and document reference
  </code></pre>
  
  <p>Moreover, I have tried BeautifulSoup but very new to it. I don't know how to do. this is the code I am doing.</p>
  
  <pre><code>def outputCluster(rFile):
      documentInReadFile = {}         #dictionary to store all document in readFile
  
      myfile = codecs.open(rFile, mode='r', encoding="utf8")
      soup = BeautifulSoup(myfile)
      # print all text in readFile:
      # print soup.prettify()
  
      # print soup.find+_all('title')
  
  outputCluster("file.xml")
  </code></pre>
  
  <p>Please kindly leave me some suggestion.
  Thank you.</p>