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.  
  11. require_once 'XML/Serializer.php';
  12.  
  13. $options = array(
  14.                     XML_SERIALIZER_OPTION_INDENT               => '    ',
  15.                     XML_SERIALIZER_OPTION_LINEBREAKS           => "\n",
  16.                     XML_SERIALIZER_OPTION_DEFAULT_TAG          => 'unnamedItem',
  17.                     XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES => false,
  18.                     XML_SERIALIZER_OPTION_ATTRIBUTES_KEY       => '_attributes',
  19.                     XML_SERIALIZER_OPTION_CONTENT_KEY          => '_content'
  20.                 );
  21.  
  22. $data = array(
  23.                 'foo' => array(
  24.                                 '_attributes' => array'version' => '1.0''foo' => 'bar' ),
  25.                                 '_content'    => 'test & test'
  26.                               ),
  27.                 'schst' => 'Stephan Schmidt'
  28.             );
  29.  
  30. $serializer = new XML_Serializer($options);
  31.  
  32. $result $serializer->serialize($data);
  33.  
  34. if ($result === true{
  35.     $xml $serializer->getSerializedData();
  36.     echo '<pre>';
  37.     echo htmlspecialchars($xml);
  38.     echo '</pre>';
  39. else {
  40.     echo '<pre>';
  41.     print_r($result);
  42.     echo '</pre>';
  43. }
  44.  
  45. ?>

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