title: XML Parsing to .txt file Python
body: <p>I need to parse this <a href="http://forecast.weather.gov/MapClick.php?lat=47.6062&amp;lon=-122.3321&amp;FcstType=digitalDWML" rel="nofollow">XML Document</a> and move the date and time into a <code>%Y-%m-%d %H:%M:%S</code> format as well as the variables <code>hourly-qpf</code> and <code>probability-of-precipitation</code> to columns in a tab-delimited .txt file.</p>
  
  <p>All I have managed to do is read in the XML file using this code:</p>
  
  <pre><code>page = urllib2.urlopen('http://forecast.weather.gov/MapClick.php?lat=47.6062&amp;lon=-122.3321&amp;FcstType=digitalDWML')
  page_content = page.read()
  with open('KBFI.xml', 'w') as fid:
      fid.write(page_content)
  </code></pre>
  
  <p>I am at a loss after this. I've only parsed one XML doc before, and it looked completely different from this.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Sorry for not having anything to give you guys before, but I wasn't sure what module to use, as I only have experience with minidom and it didn't seem like the right choice. I've been messing around with Element Tree and I have come up with this:</p>
  
  <pre><code>data = []
  import xml.etree.ElementTree as ET
  tree = ET.parse('KBFI.xml')
  root = tree.getroot()
  for data in root.findall('data'):
      for time-layout in root.findall('time-layout'):
          start-valid-time = time-layout.find('start-valid-time')
          time = datetime.datetime.strptime(start-valid-time, '%Y-%m-%dT%H:%M:%S')
      for parameters in root.findall('parameters'):
          for probability-of-precipitation in root.findall('probability-of-precipitation'):
              value = probability-of-precipitation.find('value')
      for hourly-qpf in root.findall('hourly-qpf'):
              value2 = hourly-qpf.find('value')
  data = data.append([time,
                      value,
                      value2])
  with open('KBFI.txt','w') as file:
      file.writelines('\t'.join(map(str,i)) + '\n' for i in data)
  </code></pre>
  
  <p>However, there is a problem because the variables are hyphenated and I do not know how to change them to underscores or remove them. Also, because of this, I have no idea if my code is any good!</p>