Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2315993
  • 博文数量: 473
  • 博客积分: 12252
  • 博客等级: 上将
  • 技术积分: 4307
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-12 10:02
文章分类

全部博文(473)

文章存档

2012年(8)

2011年(63)

2010年(73)

2009年(231)

2008年(98)

分类:

2010-01-25 14:36:09

XML_Serializer
例子:
 

<?php
// Set error reporting to ignore notices

error_reporting(E_ALL ^ E_NOTICE);

// Include XML_Serializer

require_once 'XML/Serializer.php';

// Some data to transform

$palette = array('red', 'green', 'blue');

// An array of serializer options

$serializer_options = array (
   'addDecl' => TRUE,
   'encoding' => 'ISO-8859-1',
   'indent' => ' ',
   'rootName' => 'palette',
   'defaultTagName' => 'color',
);

// Instantiate the serializer with the options

$Serializer = &new XML_Serializer($serializer_options);

// Serialize the data structure

$status = $Serializer->serialize($palette);

// Check whether serialization worked

if (PEAR::isError($status)) {
   die($status->getMessage());
}

// Display the XML document

header('Content-type: text/xml');
echo $Serializer->getSerializedData();
?>

结果:

<?xml version="1.0" encoding="ISO-8859-1"?>
<palette>
  <color>red</color>
  <color>green</color>
  <color>blue</color>
</palette>


在redhat下安装步骤:

  1. pear channel-update pear.php.net
  2. pear install XML_Serializer-0.20.0
阅读(1002) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~