title: How-to Serialize/Unserialize a SimpleXML Object?
body: <p>I've seen a few <a href="http://web.archive.org/web/20100211140653/http://blog.makemepulse.com/2007/09/27/serialize-and-unserialize-simplexml-in-php" rel="noreferrer">creative solutions</a> for dealing with serialized SPL objects but am looking for more options (or elaborations). I store nested serialized objects - of which, one is SimpleXML - in the database, only to be un-serialized later. This obviously cause some problems.</p>
  
  <pre><code>$s = new SimpleXmlElement('&lt;foo&gt;bar&lt;/foo&gt;');
  $ss = serialize($s);
  $su = unserialize($ss);
  // Warning: unserialize() [function.unserialize]: Node no longer exists...
  </code></pre>
  
  <p>Does anyone have any insight into highly-reliable methods for dealing with serialized SPL objects? __sleep()/__wakeup() overrides? Cast-to-stdClass? Cast-to-string, then serialize?</p>
  
  <p>Any help is appreciated.</p>
  
  <p>[<strong>Edit</strong>: The scope and variation of these XML schemas are too varied to map with an ORM. They are, at their most fundamental level, arbitrary payloads in stateful processes, triggered within restful APIs.]</p>