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

Source for file serializeNullProperties.php

Documentation is available at serializeNullProperties.php

  1. <?PHP
  2. /**
  3.  * This example demonstrates the use of
  4.  * ignoreNull => true
  5.  *
  6.  * It can be used to serialize an indexed array
  7.  * like ext/simplexml does, by using the name
  8.  * of the parent tag, while omitting this tag.
  9.  *
  10.  * @author Stephan Schmidt <schst@php.net>
  11.  */
  12.  
  13. require_once 'XML/Serializer.php';
  14.  
  15. $options = array(
  16.                     "indent"         => '    ',
  17.                     "linebreak"      => "\n",
  18.                 );
  19.  
  20. $serializer = new XML_Serializer($options);
  21.  
  22. $object = new stdClass();
  23. $object->foo = 'bar';
  24. $object->bar = null;
  25.  
  26. $array = array(
  27.                 'foo' => 'bar',
  28.                 'bar' => null
  29.             );
  30.  
  31. $result $serializer->serialize($object);
  32.  
  33. if ($result === true{
  34.     echo "<pre>";
  35.     echo htmlentities($serializer->getSerializedData());
  36.     echo "</pre>";
  37. }
  38.  
  39. $result $serializer->serialize($array);
  40.  
  41. if ($result === true{
  42.     echo "<pre>";
  43.     echo htmlentities($serializer->getSerializedData());
  44.     echo "</pre>";
  45. }
  46.  
  47. $serializer->setOption('ignoreNull'true);
  48. $result $serializer->serialize($object);
  49.  
  50. if ($result === true{
  51.     echo "<pre>";
  52.     echo htmlentities($serializer->getSerializedData());
  53.     echo "</pre>";
  54. }
  55.  
  56. $result $serializer->serialize($array);
  57.  
  58. if ($result === true{
  59.     echo "<pre>";
  60.     echo htmlentities($serializer->getSerializedData());
  61.     echo "</pre>";
  62. }
  63. ?>

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