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

Source for file unserializeWithTagMap.php

Documentation is available at unserializeWithTagMap.php

  1. <?PHP
  2. /**
  3.  * This example shows how to use the tagMap option.
  4.  *
  5.  * @author  Stephan Schmidt <schst@php.net>
  6.  */
  7.  
  8. // this is a simple XML document
  9. $xml '<root>' .
  10.        '  <foo>FOO</foo>' .
  11.        '  <bar>BAR</bar>' .
  12.        '</root>';
  13.  
  14. require_once 'XML/Unserializer.php';
  15.  
  16. // complex structures are arrays, the key is the attribute 'handle' or 'name', if handle is not present
  17. $options = array(
  18.                  XML_UNSERIALIZER_OPTION_COMPLEXTYPE => 'array',
  19.                  XML_UNSERIALIZER_OPTION_TAG_MAP     => array(
  20.                                                             'foo' => 'bar',
  21.                                                             'bar' => 'foo'
  22.                                                            )
  23.                 );
  24.  
  25. //  be careful to always use the ampersand in front of the new operator 
  26. $unserializer &new XML_Unserializer($options);
  27.  
  28. // userialize the document
  29. $status $unserializer->unserialize($xmlfalse);    
  30.  
  31. if (PEAR::isError($status)) {
  32.     echo 'Error: ' $status->getMessage();
  33. else {
  34.     $data $unserializer->getUnserializedData();
  35.     echo '<pre>';
  36.     print_r($data);
  37.     echo '</pre>';
  38. }
  39.  
  40. // a tad more complex
  41. $xml '<root>' .
  42.        '  <foo>'.
  43.        '    <tomato>45</tomato>'.
  44.        '  </foo>'.
  45.        '  <bar>'.
  46.        '    <tomato>31</tomato>'.
  47.        '  </bar>'.
  48.        '</root>';
  49.  
  50. // userialize the document
  51. $status $unserializer->unserialize($xmlfalse);    
  52.  
  53. if (PEAR::isError($status)) {
  54.     echo 'Error: ' $status->getMessage();
  55. else {
  56.     $data $unserializer->getUnserializedData();
  57.     echo '<pre>';
  58.     print_r($data);
  59.     echo '</pre>';
  60. }
  61. ?>

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