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.     error_reporting(E_ALL);
  11.  
  12.     require_once 'XML/Serializer.php';
  13.  
  14.     $options = array(
  15.                         "indent"          => "    ",
  16.                         "linebreak"       => "\n",
  17.                         "typeHints"       => false,
  18.                         "addDecl"         => true,
  19.                         "encoding"        => "UTF-8",
  20.                         "rootName"        => "rdf:RDF",
  21.                         "rootAttributes"  => array("version" => "0.91"),
  22.                         "defaultTagName"  => "item",
  23.                         "attributesArray" => "_attributes"
  24.                     );
  25.     
  26.     $serializer = new XML_Serializer($options);
  27.  
  28.     
  29.     $rdf    =   array(
  30.                         "channel" => array(
  31.                                             "title" => "Example RDF channel",
  32.                                             "link"  => "http://www.php-tools.de",
  33.                                             "image"    =>    array(
  34.                                                                 "title"    => "Example image",
  35.                                                                 "url"    =>    "http://www.php-tools.de/image.gif",
  36.                                                                 "link"    =>    "http://www.php-tools.de"
  37.                                                             ),
  38.                                             "_attributes" => array"rdf:about" => "http://example.com/foobar.html" ),
  39.                                             array(
  40.                                                 "title"    => "Example item",
  41.                                                 "link"    => "http://example.com",
  42.                                                 "_attributes" => array"rdf:about" => "http://example.com/foobar.html" )
  43.                                             ),
  44.                                             array(
  45.                                                 "title"    => "Another item",
  46.                                                 "link"    => "http://example.com",
  47.                                                 "_attributes" => array"rdf:about" => "http://example.com/foobar.html" )
  48.                                             ),
  49.                                             array(
  50.                                                 "title"    => "I think you get it...",
  51.                                                 "link"    => "http://example.com",
  52.                                                 "_attributes" => array"rdf:about" => "http://example.com/foobar.html" )
  53.                                             )
  54.                                         )
  55.                     );
  56.     
  57.     $result $serializer->serialize($rdf);
  58.     
  59.     if$result === true {
  60.         echo    "<pre>";
  61.         echo    htmlentities($serializer->getSerializedData());
  62.         echo    "</pre>";
  63.     }
  64. ?>

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