Normalize in canonical form two XML files in Python
<p>I have two XML files and I need to check that they contains the same exact information.</p>

<p>Regardless of tag or attribute order.</p>

<p>For instance this two XML files should be equals:</p>

<p><strong>test1.xml</strong></p>

<pre><code>&lt;blocklist lastupdate="1459262434336" xmlns="http://www.mozilla.org/2006/addons-blocklist"&gt;
  &lt;emItems&gt;
    &lt;emItem blockID="i454" id="sqlmoz@facebook.com"&gt;
      &lt;versionRange minVersion="0" maxVersion="*" severity="3"&gt;
        &lt;targetApplication id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"&gt;
          &lt;versionRange maxVersion="3.6.*" minVersion="3.6"/&gt;
        &lt;/targetApplication&gt;
      &lt;/versionRange&gt;
      &lt;versionRange maxVersion="*" minVersion="0"/&gt;
      &lt;prefs&gt;
        &lt;pref&gt;test.blocklist&lt;/pref&gt;
      &lt;/prefs&gt;
    &lt;/emItem&gt;
  &lt;/emItems&gt;
&lt;/blocklist&gt;
</code></pre>

<p><strong>test2.xml</strong></p>

<pre><code>&lt;blocklist lastupdate="1459262434336" xmlns="http://www.mozilla.org/2006/addons-blocklist"&gt;
  &lt;emItems&gt;
    &lt;emItem blockID="i454" id="sqlmoz@facebook.com"&gt;
      &lt;prefs&gt;
        &lt;pref&gt;test.blocklist&lt;/pref&gt;
      &lt;/prefs&gt;
      &lt;versionRange minVersion="0" maxVersion="*" severity="3"&gt;
        &lt;targetApplication id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"&gt;
          &lt;versionRange maxVersion="3.6.*" minVersion="3.6"/&gt;
        &lt;/targetApplication&gt;
      &lt;/versionRange&gt;
      &lt;versionRange minVersion="0" maxVersion="*"/&gt;
    &lt;/emItem&gt;
  &lt;/emItems&gt;
&lt;/blocklist&gt;
</code></pre>

<p>I tried to find some solutions like:</p>

<ul>
<li><a href="https://www.logilab.org/859" rel="nofollow noreferrer">xmldiff</a></li>
<li><a href="http://www.decalage.info/fr/python/lxml-c14n" rel="nofollow noreferrer">lxml-c14n</a></li>
<li><a href="https://www.safaribooksonline.com/library/view/python-cookbook/0596001673/ch12s09.html" rel="nofollow noreferrer">xml.dom</a></li>
</ul>

<p>I am also going to try <a href="https://stackoverflow.com/a/33521000/186202">this solution</a></p>

<p>But do you have any idea of what would be my options here? Isn't XML Normalization and Canonicalization supposed to handle this for me?</p>

<p>what am I doing wrong here?</p>

<p>If I were to do it in JSON I would use: <code>json.dumps(data, sort_keys=True, separators=(',', ':'))</code></p>