<?php /** * This example shows how to create an RDF document * with a few lines of code. * This can also be done with mode => simplexml * * @author Stephan Schmidt <*****@*****.**> * @see serializeIndexedArray.php */ error_reporting(E_ALL); require_once 'XML/Serializer.php'; $options = array("indent" => " ", "linebreak" => "\n", "typeHints" => false, "addDecl" => true, "encoding" => "UTF-8"); $serializer = new XML_Serializer($options); $serializer->setErrorHandling(PEAR_ERROR_DIE); $array = array(new stdClass(), new stdClass()); $result = $serializer->serialize($array); if ($result === true) { echo "<pre>"; echo htmlentities($serializer->getSerializedData()); echo "</pre>"; } $result = $serializer->serialize($array, array('classAsTagName' => true)); if ($result === true) { echo "<pre>"; echo htmlentities($serializer->getSerializedData()); echo "</pre>"; }
/** * Return xml version of result set. */ function serializeArray($resultList) { $options = array(XML_SERIALIZER_OPTION_XML_DECL_ENABLED => false, XML_SERIALIZER_OPTION_DOCTYPE_ENABLED => false, XML_SERIALIZER_OPTION_INDENT => " ", XML_SERIALIZER_OPTION_LINEBREAKS => "\n", XML_SERIALIZER_OPTION_TYPEHINTS => false, XML_SERIALIZER_OPTION_XML_ENCODING => "UTF-8?", XML_SERIALIZER_OPTION_ROOT_NAME => "results", XML_SERIALIZER_OPTION_DEFAULT_TAG => "result", XML_SERIALIZER_OPTION_CDATA_SECTIONS => true); // instatiate the serializer object $serializer = new XML_Serializer($options); $serializer->setErrorHandling(PEAR_ERROR_DIE); // serialze the data $status = $serializer->serialize($resultList); // check whether serialization worked if (PEAR::isError($status)) { die($status->getMessage()); } // get the serialized data $xml = $serializer->getSerializedData(); header("Content-type: text/xml; charset=UTF-8"); //header("Content-Transfer-Encoding: binary\n"); // return the xml $xml = html_entity_decode($xml, ENT_QUOTES, 'UTF-8'); $xml = stripslashes($xml); $xml = trim($xml); echo $xml; }