本文整理汇总了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;
}