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

Source for file serializeWithAttributes2.php

Documentation is available at serializeWithAttributes2.php

  1. <?PHP
  2. /**
  3.  * XML Serializer example
  4.  *
  5.  * This example demonstrates, how XML_Serializer is able
  6.  * to serialize predefined values as the attributes of a tag
  7.  *
  8.  * @author  Stephan Schmidt <schst@php.net>
  9.  */
  10.     error_reporting(E_ALL);
  11.  
  12.     require_once 'XML/Serializer.php';
  13.  
  14.     $options = array(
  15.                         "indent"             => "    ",
  16.                         "linebreak"          => "\n",
  17.                         "defaultTagName"     => "unnamedItem",
  18.                         "scalarAsAttributes" => false,
  19.                         "attributesArray"    => '_attributes',
  20.                         "contentName"        => '_content'
  21.                     );
  22.  
  23.     $data = array(
  24.                     'foo' => array(
  25.                                     '_attributes' => array'version' => '1.0''foo' => 'bar' ),
  26.                                     '_content'    => 'test'
  27.                                   ),
  28.                     'schst' => 'Stephan Schmidt'
  29.                 );    
  30.     
  31.     $serializer = new XML_Serializer($options);
  32.     
  33.     $result $serializer->serialize($data);
  34.     
  35.     if$result === true {
  36.         $xml $serializer->getSerializedData();
  37.  
  38.         echo    "<pre>";
  39.         print_rhtmlspecialchars($xml) );
  40.         echo    "</pre>";
  41.     else {
  42.         echo    "<pre>";
  43.         print_r($result);
  44.         echo    "</pre>";
  45.     }
  46.  
  47. ?>

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