title: Parsing an xml file with an ordered dictionary
body: <p>I have an <code>xml</code> file of the form:</p>
  
  <pre><code>&lt;NewDataSet&gt;
      &lt;Root&gt;
          &lt;Phonemic&gt;and&lt;/Phonemic&gt;
          &lt;Phonetic&gt;nd&lt;/Phonetic&gt;
          &lt;Description/&gt;
          &lt;Start&gt;0&lt;/Start&gt;
          &lt;End&gt;8262&lt;/End&gt;
      &lt;/Root&gt;
      &lt;Root&gt;
          &lt;Phonemic&gt;comfortable&lt;/Phonemic&gt;
          &lt;Phonetic&gt;comfetebl&lt;/Phonetic&gt;
          &lt;Description&gt;adj&lt;/Description&gt;
          &lt;Start&gt;61404&lt;/Start&gt;
          &lt;End&gt;72624&lt;/End&gt;
      &lt;/Root&gt;
  &lt;/NewDataSet&gt;
  </code></pre>
  
  <p>I need to process it so that, for instance, when the user inputs <code>nd</code>, the program matches it with the <code>&lt;Phonetic&gt;</code> tag and returns <code>and</code> from the <code>&lt;Phonemic&gt;</code> part. I thought maybe if I can convert the xml file to a dictionary, I would be able to iterate over the data and find information when needed. </p>
  
  <p>I searched and found <a href="https://github.com/martinblech/xmltodict" rel="nofollow">xmltodict</a> which is used for the same purpose:</p>
  
  <pre><code>import xmltodict
  with open(r'path\to\1.xml', encoding='utf-8', errors='ignore') as fd:
      obj = xmltodict.parse(fd.read())
  </code></pre>
  
  <p>Running this gives me an <code>ordered dict</code>:</p>
  
  <pre><code>&gt;&gt;&gt; obj
  OrderedDict([('NewDataSet', OrderedDict([('Root', [OrderedDict([('Phonemic', 'and'), ('Phonetic', 'nd'), ('Description', None), ('Start', '0'), ('End', '8262')]), OrderedDict([('Phonemic', 'comfortable'), ('Phonetic', 'comfetebl'), ('Description', 'adj'), ('Start', '61404'), ('End', '72624')])])]))])
  </code></pre>
  
  <p>Now this unfortunately hasn't made things simpler and I am not sure how to go about implementing the program with the new data structure. For example to access <code>nd</code> I'd have to write:</p>
  
  <pre><code>obj['NewDataSet']['Root'][0]['Phonetic']
  </code></pre>
  
  <p>which is ridiculously complicated. I tried to make it into a regular dictionary by <code>dict()</code> but as it is nested, the inner layers remain ordered and my data is so big.</p>