XML_Serializer
[ class tree: XML_Serializer ] [ index: XML_Serializer ] [ all elements ]

Source for file serializeWithComment.php

Documentation is available at serializeWithComment.php

  1. <?PHP
  2. /**
  3.  * This is just a basic example that shows
  4.  * how objects can be serialized so they can
  5.  * be fully restored later.
  6.  *
  7.  * @author Stephan Schmidt <schst@php.net>
  8.  */
  9.  
  10. require_once 'XML/Serializer.php';
  11.  
  12. $options = array(
  13.                     XML_SERIALIZER_OPTION_INDENT      => '    ',
  14.                     XML_SERIALIZER_OPTION_LINEBREAKS  => "\n",
  15.                     XML_SERIALIZER_OPTION_COMMENT_KEY => 'comment'
  16.                 );
  17.  
  18. $foo = new stdClass;
  19. $foo->comment = 'This is a comment';
  20. $foo->value   = 'My value';
  21.  
  22. $foo->bar     = new stdClass();
  23. $foo->bar->value   = 'Another value';
  24. $foo->bar->comment = 'Another comment';
  25.  
  26. $foo->tomato          = new stdClass();
  27. $foo->tomato->comment = 'And a last comment';
  28.  
  29. $serializer &new XML_Serializer($options);
  30.  
  31. $result $serializer->serialize($foo);
  32.  
  33. if ($result === true{
  34.     $xml $serializer->getSerializedData();
  35. }
  36.  
  37. echo '<pre>';
  38. echo htmlspecialchars($xml);
  39. echo '</pre>';
  40. ?>

Documentation generated on Mon, 11 Mar 2019 15:41:41 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.