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

Source for file unserializeObject.php

Documentation is available at unserializeObject.php

  1. <?PHP
  2. /**
  3.  * This example shows how XML_Serializer and XML_Unserializer
  4.  * work together.
  5.  *
  6.  * A structure is serialized and later it's unserialized from the
  7.  * resulting XML document.
  8.  *
  9.  * @author  Stephan Schmidt <schst@php.net>
  10.  */
  11.  
  12.     require_once 'XML/Serializer.php';
  13.     require_once 'XML/Unserializer.php';
  14.     // this is just to get a nested object
  15.     $pearError = PEAR::raiseError('This is just an error object',123);
  16.     
  17.     $options = array(
  18.                         "indent"         => "    ",
  19.                         "linebreak"      => "\n",
  20.                         "defaultTagName" => "unnamedItem",
  21.                         "typeHints"      => true
  22.                     );
  23.     
  24.     $foo    =   new stdClass;
  25.     
  26.     $foo->value = "My value";
  27.     $foo->error = $pearError;
  28.     $foo->xml   = array"This is" => "cool" );
  29.     $foo->resource   = fopen"../package.xml""r" );
  30.     
  31.     $serializer = new XML_Serializer($options);
  32.     
  33.     $result $serializer->serialize($foo);
  34.     
  35.     if$result === true {
  36.         $xml $serializer->getSerializedData();
  37.     }
  38.  
  39.     echo    "<pre>";
  40.     print_rhtmlspecialchars($xml) );
  41.     echo    "</pre>";
  42.     
  43.     //  be careful to always use the ampersand in front of the new operator 
  44.     $unserializer &new XML_Unserializer();
  45.  
  46.     $status $unserializer->unserialize($xml);    
  47.  
  48.     if (PEAR::isError($status)) {
  49.         echo    "Error: " $status->getMessage();
  50.     else {
  51.         $data $unserializer->getUnserializedData();
  52.  
  53.         echo    "<pre>";
  54.         var_dump$data );
  55.         echo    "</pre>";
  56.     }
  57. ?>

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