title: Comparing two XML strings/files in Groovy/Java
body: <p>I'm writing unit tests for checking some XML builder.</p>
  
  <p>Now I'm running into the problem of syntactical differences between the expected result and the actual result, despite their identical semantics.</p>
  
  <p><strong>Example:</strong></p>
  
  <p><em><strong>Expected result:</em></strong></p>
  
  <pre><code>&lt;parent&gt;&lt;child attr="test attribute"&gt;text here&lt;/child&gt;&lt;/parent&gt;
  </code></pre>
  
  <p><em><strong>Actual result:</em></strong></p>
  
  <pre><code>&lt;parent&gt;
    &lt;child attr="test attribute"&gt;
      text here
    &lt;/child&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>I tried normalizing the xml using XmlUtil.serialize(), however this seems to keep the whitespaces, leaving syntactical differences.</p>
  
  <p>How can I get the normalized/canonical form of xml strings in order to make my tests more robust?</p>
  
  <p>I'm writing a Grails application, so I'm fine with any solution in Groovy or Java.</p>