title: Sort nodes after using getElementsByTagName by the nodes attributes
body: <p><strong>EDIT</strong></p>
  
  <p>The dictionary is the offender here, the answer marked on this question works, the dictionary does what it wants though. Sorting the dictionary is the answer in this case, but now I know how to sort nodes via attributes and so do you.</p>
  
  <p><strong>END</strong></p>
  
  <p>I am so happy to be asking Python questions, here is what I have:</p>
  
  <pre><code>def parse_fixed_data(self, format):
      return_message = {}
      nodes = format.getElementsByTagName('data')
      for node in nodes:
          return_message[node.attributes['name'].value] = self.raw_message[int(node.attributes['from'].value):int(node.attributes['to'].value)] 
      return return_message
  </code></pre>
  
  <p>This works almost beautifully. The 'format' variable is an already parsed node, which contains a bunch of 'data' nodes. Here is the xml:</p>
  
  <pre><code>&lt;pmbmsg id='pmb_header'&gt;
      &lt;version maj='01' min='00' rev='0000' type='FIXED' delimeter=''&gt;
          &lt;data seq='1'   from='0'   to='3'    name='message_type'/&gt;
          &lt;data seq='2'   from='3'   to='13'   name='version'/&gt;
          &lt;data seq='3'   from='13'  to='33'   name='from_system'/&gt;
          &lt;data seq='4'   from='33'  to='53'   name='to_system'/&gt;
          &lt;data seq='5'   from='53'  to='73'   name='family'/&gt;
          &lt;data seq='6'   from='73'  to='83'   name='priority'/&gt;
          &lt;data seq='7'   from='83'  to='103'  name='msg_format_id'/&gt;
          &lt;data seq='8'   from='103' to='135'  name='msg_unique_id'/&gt;
          &lt;data seq='9'   from='135' to='161'  name='created'/&gt;
          &lt;data seq='10'  from='161' to='163'  name='hop_count'/&gt;
          &lt;data seq='11'  from='163' to='173'  name='original_msg_format_id'/&gt;
          &lt;data seq='12'  from='173' to='205'  name='original_unique_id'/&gt;
          &lt;data seq='13'  from='205' to='245'  name='padding'/&gt;
          &lt;data seq='14'  from='245' to='4086' name='message_data'/&gt;
      &lt;/version&gt;
  &lt;/pmbmsg&gt;
  </code></pre>
  
  <p>Well this works all well and good but I get the dictionary elements back in this order:</p>
  
  <pre><code>u'to_system'            
  u'padding'          
  u'original_msg_format_id'   
  u'original_unique_id'       
  u'family'           
  u'created'          
  u'msg_format_id'        
  u'hop_count'            
  u'msg_unique_id'            
  u'priority'         
  u'version'          
  u'from_system'          
  u'message_type'         
  u'message_data'
  </code></pre>
  
  <p>(values removed)</p>
  
  <p>I would like them to come back in the order they appear in the xml, and there seq attribute could help this. After this line in the Python code:</p>
  
  <pre><code>nodes = format.getElementsByTagName('data')
  </code></pre>
  
  <p>...is there some function I could run on nodes that would sort this? Or is there something I could state when getting the nodes that would let it know to sort them? You would think that it would just naturally get it in the order the xml is written? </p>
  
  <p>If there is no function to do this auto-magically for me, I can handle hacking it.</p>