title: How to parse a .txt file into .xml?
body: <p>This is my txt file:</p>
  
  <pre class="lang-none prettyprint-override"><code>In File Name:   C:\Users\naqushab\desktop\files\File 1.m1
  Out File Name:  C:\Users\naqushab\desktop\files\Output\File 1.m2
  In File Size:   Low:    22636   High:   0
  Total Process time: 1.859000
  Out File Size:  Low:    77619   High:   0
  
  In File Name:   C:\Users\naqushab\desktop\files\File 2.m1
  Out File Name:  C:\Users\naqushab\desktop\files\Output\File 2.m2
  In File Size:   Low:    20673   High:   0
  Total Process time: 3.094000
  Out File Size:  Low:    94485   High:   0
  
  In File Name:   C:\Users\naqushab\desktop\files\File 3.m1
  Out File Name:  C:\Users\naqushab\desktop\files\Output\File 3.m2
  In File Size:   Low:    66859   High:   0
  Total Process time: 3.516000
  Out File Size:  Low:    217268  High:   0
  </code></pre>
  
  <p>I am trying to parse this to an XML format like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;root&gt;
      &lt;filedata&gt;
          &lt;InFileName&gt;File 1.m1&lt;/InFileName&gt;
          &lt;OutFileName&gt;File 1.m2&lt;/OutFileName&gt;
          &lt;InFileSize&gt;22636&lt;/InFileSize&gt;
          &lt;OutFileSize&gt;77619&lt;/OutFileSize&gt;
          &lt;ProcessTime&gt;1.859000&lt;/ProcessTime&gt;
      &lt;/filedata&gt;
      &lt;filedata&gt;
          &lt;InFileName&gt;File 2.m1&lt;/InFileName&gt;
          &lt;OutFileName&gt;File 2.m2&lt;/OutFileName&gt;
          &lt;InFileSize&gt;20673&lt;/InFileSize&gt;
          &lt;OutFileSize&gt;94485&lt;/OutFileSize&gt;
          &lt;ProcessTime&gt;3.094000&lt;/ProcessTime&gt;
      &lt;/filedata&gt;
      &lt;filedata&gt;
          &lt;InFileName&gt;File 3.m1&lt;/InFileName&gt;
          &lt;OutFileName&gt;File 3.m2&lt;/OutFileName&gt;
          &lt;InFileSize&gt;66859&lt;/InFileSize&gt;
          &lt;OutFileSize&gt;217268&lt;/OutFileSize&gt;
          &lt;ProcessTime&gt;3.516000&lt;/ProcessTime&gt;
      &lt;/filedata&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>Here is the code (I am using Python 2) in which I am trying to achieve that:</p>
  
  <pre><code>import re
  import xml.etree.ElementTree as ET
  
  rex = re.compile(r'''(?P&lt;title&gt;In File Name:
                         |Out File Name:
                         |In File Size:   Low:
                         |Total Process time:
                         |Out File Size:  Low:
                       )
                       (?P&lt;value&gt;.*)
                       ''', re.VERBOSE)
  
  root = ET.Element('root')
  root.text = '\n'    # newline before the celldata element
  
  with open('Performance.txt') as f:
      celldata = ET.SubElement(root, 'filedata')
      celldata.text = '\n'    # newline before the collected element
      celldata.tail = '\n\n'  # empty line after the celldata element
      for line in f:
          # Empty line starts new celldata element (hack style, uggly)
          if line.isspace():
              celldata = ET.SubElement(root, 'filedata')
              celldata.text = '\n'
              celldata.tail = '\n\n'
  
          # If the line contains the wanted data, process it.
          m = rex.search(line)
          if m:
              # Fix some problems with the title as it will be used
              # as the tag name.
              title = m.group('title')
              title = title.replace('&amp;', '')
              title = title.replace(' ', '')
  
              e = ET.SubElement(celldata, title.lower())
              e.text = m.group('value')
              e.tail = '\n'
  
  # Display for debugging
  ET.dump(root)
  
  # Include the root element to the tree and write the tree
  # to the file.
  tree = ET.ElementTree(root)
  tree.write('Performance.xml', encoding='utf-8', xml_declaration=True)
  </code></pre>
  
  <p>But I am getting empty values, is it possible to parse this txt to XML?</p>