title: How to check if a DomDocument was changed with a simple and fast comparison?
body: <p>I need only to  compare the same <code>DomDocument</code> object before and after some operation, a &quot;fast check&quot; if the operation changed the object... I need some <code>serialize_DomDocument()</code> (<strong>exists something like?</strong>) that can be used in the following context:</p>
  <ol>
  <li><p><code>$obj</code> is a <a href="http://www.php.net/manual/en/class.domdocument.php" rel="nofollow noreferrer">DomDocumemt</a> object (the &quot;state of the object&quot; is the value of all properties and all documentElement contents).</p>
  </li>
  <li><p><code>$dump = serialize_DomDocument($obj)</code>   <strong>How to do it??</strong> How to dump the state of the object?   ... Not translating all to XML by <code>saveXML()</code> method, but only (FASTER!) coping all binary representarion (of the object pointed by <code>$obj</code>) to <code>$dump</code>.</p>
  </li>
  <li><p>perform some operation (ex. remove a node or change an attribute or &quot;do nothing&quot;)</p>
  </li>
  <li><p><code>if ($dump != serialize_DomDocument($obj))</code> or something like it, checking if <code>$obj</code> changed. Fast comparison. <strong>The operation was &quot;do nothing&quot; or &quot;do something&quot;?</strong></p>
  </li>
  </ol>
  <h2>Alternative solution...</h2>
  <p>Not the ideal, but solve some cases... There are some operations (ex.  only <code>appendChild</code>'s or only <code>removeChild</code>'s) where the change always affect the number of nodes, so, for that kind of operations, <strong>to check total number of nodes</strong> or <em>total length</em>, is enough.</p>
  <p><strong>How to check faster than <code>saveXML()</code>?</strong></p>
  <hr />
  <h2>NOTES</h2>
  <p><em>NOTE-1</em>: as remembered by <a href="http://halufa.blogspot.com.br/2010/02/php-serialize-domdocument.html" rel="nofollow noreferrer">this post</a>, you can not serialize a DomDocument Object.</p>
  <p><em>NOTE-2</em>: is not a problem of <a href="https://stackoverflow.com/q/141993/287948">comparing two distinct DOM objects</a>, but something more easy, because not change IDs, etc. not need canonical representation (!), only access to internal representation.</p>
  <hr />
  <h2>EDIT AFTER BOUNTY</h2>
  <p>This question <strong>is not about &quot;how controll changes or a change-flag&quot;</strong>, please read with attention the question.</p>
  <p>This question <strong>is not a request of theoretical reviews</strong>.</p>
  <h2>EDIT2</h2>
  <p>Perhaps the solution is about &quot;low level&quot;... I not understand if the &quot;binary representation&quot; is the &quot;dump&quot; or have another name, see:</p>
  <ul>
  <li><a href="https://stackoverflow.com/q/8232094/287948">libxml xmlNodePtr to raw xml string?</a></li>
  <li><a href="http://xmlsoft.org/html/libxml-tree.html#xmlBufNodeDump" rel="nofollow noreferrer">http://xmlsoft.org/html/libxml-tree.html#xmlBufNodeDump</a></li>
  <li>...</li>
  </ul>