本文整理匯總了PHP中XML_Serializer::setErrorHandling方法的典型用法代碼示例。如果您正苦於以下問題:PHP XML_Serializer::setErrorHandling方法的具體用法?PHP XML_Serializer::setErrorHandling怎麽用?PHP XML_Serializer::setErrorHandling使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類XML_Serializer
的用法示例。
在下文中一共展示了XML_Serializer::setErrorHandling方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: array
<?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 <schst@php.net>
* @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>";
}
示例2: serializeArray
/**
* 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;
}