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.     error_reporting(E_ALL);
  12.  
  13.     require_once 'XML/Serializer.php';
  14.     require_once 'XML/Unserializer.php';
  15.     // this is just to get a nested object
  16.     $pearError = PEAR::raiseError('This is just an error object',123);
  17.     
  18.     $options = array(
  19.                         "indent"         => "    ",
  20.                         "linebreak"      => "\n",
  21.                         "defaultTagName" => "unnamedItem",
  22.                         "typeHints"      => true
  23.                     );
  24.     
  25.     $foo    =   new stdClass;
  26.     
  27.     $foo->value = "My value";
  28.     $foo->error = $pearError;
  29.     $foo->xml   = array"This is" => "cool" );
  30.     $foo->resource   = fopen"../package.xml""r" );
  31.     
  32.     $serializer = new XML_Serializer($options);
  33.     
  34.     $result $serializer->serialize($foo);
  35.     
  36.     if$result === true {
  37.         $xml $serializer->getSerializedData();
  38.     }
  39.  
  40.     echo    "<pre>";
  41.     print_rhtmlspecialchars($xml) );
  42.     echo    "</pre>";
  43.     
  44.     //  be careful to always use the ampersand in front of the new operator 
  45.     $unserializer &new XML_Unserializer();
  46.  
  47.     $status $unserializer->unserialize($xml);    
  48.  
  49.     if (PEAR::isError($status)) {
  50.         echo    "Error: " $status->getMessage();
  51.     else {
  52.         $data $unserializer->getUnserializedData();
  53.  
  54.         echo    "<pre>";
  55.         var_dump$data );
  56.         echo    "</pre>";
  57.     }
  58. ?>

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