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

Source for file unserializeEnum.php

Documentation is available at unserializeEnum.php

  1. <?PHP
  2. /**
  3.  * This example shows how to use the XML_UNSERIALIZER_OPTION_FORCE_ENUM
  4.  * option
  5.  *
  6.  * @author  Stephan Schmidt <schst@php.net>
  7.  */
  8.  
  9. require_once 'XML/Unserializer.php';
  10.  
  11. $xml1 '<root>
  12.    <item>
  13.      <name>schst</name>
  14.    </item>
  15.    <item>
  16.      <name>luckec</name>
  17.    </item>
  18.  </root>';
  19.     
  20. $xml2 '<root>
  21.    <item>
  22.      <name>schst</name>
  23.    </item>
  24.  </root>';
  25.     
  26. $options = array(
  27.                   XML_UNSERIALIZER_OPTION_FORCE_ENUM => array('item')
  28.                 );
  29.  
  30.                 
  31. //  be careful to always use the ampersand in front of the new operator 
  32. $unserializer &new XML_Unserializer($options);
  33.  
  34. // userialize the document
  35. $status $unserializer->unserialize($xml1);
  36.  
  37. if (PEAR::isError($status)) {
  38.     echo 'Error: ' $status->getMessage();
  39. else {
  40.     $data $unserializer->getUnserializedData();
  41.     echo '<pre>';
  42.     print_r($data);
  43.     echo '</pre>';
  44. }
  45.  
  46. // userialize the document
  47. $status $unserializer->unserialize($xml2);
  48.  
  49. if (PEAR::isError($status)) {
  50.     echo 'Error: ' $status->getMessage();
  51. else {
  52.     $data $unserializer->getUnserializedData();
  53.     echo '<pre>';
  54.     print_r($data);
  55.     echo '</pre>';
  56. }
  57. ?>

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