title: How do I test XML equality in Ruby?
body: <p>Clearly I need to (a) convert both strings to <a href="http://www.w3.org/TR/xml-c14n" rel="noreferrer">canonical XML</a> or (b) compare their parse-trees.  The following doesn't work because the document object returned doesn't have a sensible <code>==</code> defined.</p>
  
  <pre><code>Nokogiri.XML(doc_a) == Nokogiri.XML(doc_b)
  </code></pre>
  
  <p>Nor does the following, because Nokogiri's <code>to_xml</code> leaves some internal whitespace:</p>
  
  <pre><code>Nokogiri.XML(doc_a).to_xml == Nokogiri.XML(doc_b).to_xml
  </code></pre>
  
  <p>This is a reasonable approximation of equality (and will work for most cases), but it's not quite right:</p>
  
  <pre><code>Nokogiri.XML(doc_a).to_xml.squeeze(' ') == Nokogiri.XML(doc_b).to_xml.squeeze(' ')
  </code></pre>
  
  <p>I'm already using Nokogiri, so I'd prefer to stick with it, but I'll use whatever library works.</p>