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.     error_reporting(E_ALL);
  10.  
  11.     require_once 'XML/Serializer.php';
  12.  
  13.     $options = array(
  14.                         XML_SERIALIZER_OPTION_INDENT      => '    ',
  15.                         XML_SERIALIZER_OPTION_LINEBREAKS  => "\n",
  16.                         XML_SERIALIZER_OPTION_COMMENT_KEY => 'comment'
  17.                     );
  18.     
  19.     $foo = new stdClass;
  20.     $foo->comment = 'This is a comment';
  21.     $foo->value   = 'My value';
  22.     
  23.     $foo->bar     = new stdClass();
  24.     $foo->bar->value   = 'Another value';
  25.     $foo->bar->comment = 'Another comment';
  26.     
  27.     $foo->tomato          = new stdClass();
  28.     $foo->tomato->comment = 'And a last comment';
  29.     
  30.     $serializer &new XML_Serializer($options);
  31.     
  32.     $result $serializer->serialize($foo);
  33.     
  34.     if ($result === true{
  35.         $xml $serializer->getSerializedData();
  36.     }
  37.  
  38.     echo '<pre>';
  39.     print_r(htmlspecialchars($xml));
  40.     echo '</pre>';
  41. ?>

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