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

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