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

Source for file serializeRDF.php

Documentation is available at serializeRDF.php

  1. <?PHP
  2. /**
  3.  * This example shows how to create an RDF document
  4.  * with a few lines of code.
  5.  * This can also be done with mode => simplexml
  6.  *
  7.  * @author Stephan Schmidt <schst@php.net>
  8.  * @see    serializeIndexedArray.php
  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_TYPEHINTS        => false,
  17.                     XML_SERIALIZER_OPTION_XML_DECL_ENABLED => true,
  18.                     XML_SERIALIZER_OPTION_XML_ENCODING     => 'UTF-8',
  19.                     XML_SERIALIZER_OPTION_ROOT_NAME        => 'rdf:RDF',
  20.                     XML_SERIALIZER_OPTION_ROOT_ATTRIBS     => array('version' => '0.91'),
  21.                     XML_SERIALIZER_OPTION_DEFAULT_TAG      => 'item',
  22.                     XML_SERIALIZER_OPTION_ATTRIBUTES_KEY   => '_attributes'
  23.                 );
  24.  
  25. $serializer = new XML_Serializer($options);
  26.  
  27.  
  28. $rdf    =   array(
  29.                     "channel" => array(
  30.                                         "title" => "Example RDF channel",
  31.                                         "link"  => "http://www.php-tools.de",
  32.                                         "image"    =>    array(
  33.                                                             "title"    => "Example image",
  34.                                                             "url"    =>    "http://www.php-tools.de/image.gif",
  35.                                                             "link"    =>    "http://www.php-tools.de"
  36.                                                         ),
  37.                                         "_attributes" => array"rdf:about" => "http://example.com/foobar.html" ),
  38.                                         array(
  39.                                             "title"    => "Example item",
  40.                                             "link"    => "http://example.com",
  41.                                             "_attributes" => array"rdf:about" => "http://example.com/foobar.html" )
  42.                                         ),
  43.                                         array(
  44.                                             "title"    => "Another item",
  45.                                             "link"    => "http://example.com",
  46.                                             "_attributes" => array"rdf:about" => "http://example.com/foobar.html" )
  47.                                         ),
  48.                                         array(
  49.                                             "title"    => "I think you get it...",
  50.                                             "link"    => "http://example.com",
  51.                                             "_attributes" => array"rdf:about" => "http://example.com/foobar.html" )
  52.                                         )
  53.                                     )
  54.                 );
  55.  
  56. $result $serializer->serialize($rdf);
  57.  
  58. if ($result === true{
  59.     echo "<pre>";
  60.     echo htmlentities($serializer->getSerializedData());
  61.     echo "</pre>";
  62. }
  63. ?>

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