[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libs/Xml/ -> Serializer.php (sommaire)

XML_Serializer Creates XML documents from PHP data structures like arrays, objects or scalars.

Author: Stephan Schmidt <schst@php.net>
Copyright: 1997-2005 The PHP Group
License: http://www.php.net/license/3_0.txt PHP License 3.0
Version: CVS: $Id: Serializer.php,v 1.1 2005/12/06 01:50:39 matthieu_ Exp $
Poids: 945 lignes (36 kb)
Inclus ou requis: 2 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 1 class

XML_Serializer:: (11 méthodes):
  XML_Serializer()
  apiVersion()
  resetOptions()
  setOption()
  setOptions()
  serialize()
  getSerializedData()
  _serializeValue()
  _serializeArray()
  _serializeObject()
  _createXMLTag()


Classe: XML_Serializer  - X-Ref

Creates XML documents from PHP data structures like arrays, objects or scalars.

this class can be used in two modes:

1. create an XML document from an array or object that is processed by other
applications. That means, you can create a RDF document from an array in the
following format:

$data = array(
'channel' => array(
'title' => 'Example RDF channel',
'link'  => 'http://www.php-tools.de',
'image' => array(
'title' => 'Example image',
'url'   => 'http://www.php-tools.de/image.gif',
'link'  => 'http://www.php-tools.de'
),
array(
'title' => 'Example item',
'link'  => 'http://example.com'
),
array(
'title' => 'Another Example item',
'link'  => 'http://example.org'
)
)
);

to create a RDF document from this array do the following:

require_once 'XML/Serializer.php';

$options = array(
XML_SERIALIZER_OPTION_INDENT      => "\t",        // indent with tabs
XML_SERIALIZER_OPTION_LINEBREAKS  => "\n",        // use UNIX line breaks
XML_SERIALIZER_OPTION_ROOT_NAME   => 'rdf:RDF',   // root tag
XML_SERIALIZER_OPTION_DEFAULT_TAG => 'item'       // tag for values with numeric keys
);

$serializer = new XML_Serializer($options);
$rdf        = $serializer->serialize($data);

You will get a complete XML document that can be processed like any RDF document.

2. this classes can be used to serialize any data structure in a way that it can
later be unserialized again.
XML_Serializer will store the type of the value and additional meta information
in attributes of the surrounding tag. This meat information can later be used
to restore the original data structure in PHP. If you want XML_Serializer
to add meta information to the tags, add

XML_SERIALIZER_OPTION_TYPEHINTS => true

to the options array in the constructor.

XML_Serializer( $options = null )   X-Ref
constructor

param: mixed   $options    array containing options for the serialization

apiVersion()   X-Ref
return API version

return: string  $version API version

resetOptions()   X-Ref
reset all options to default options


setOption($name, $value)   X-Ref
set an option

You can use this method if you do not want to set all options in the constructor


setOptions($options)   X-Ref
sets several options at once

You can use this method if you do not want to set all options in the constructor


serialize($data, $options = null)   X-Ref
serialize data

param: mixed    $data data to serialize
return: boolean  true on success, pear error on failure

getSerializedData()   X-Ref
get the result of the serialization

return: string serialized XML

_serializeValue($value, $tagName = null, $attributes = array()   X-Ref
serialize any value

This method checks for the type of the value and calls the appropriate method

param: mixed     $value
param: string    $tagName
param: array     $attributes
return: string

_serializeArray(&$array, $tagName = null, $attributes = array()   X-Ref
serialize an array

param: array   $array       array to serialize
param: string  $tagName     name of the root tag
param: array   $attributes  attributes for the root tag
return: string  $string      serialized data

_serializeObject(&$object, $tagName = null, $attributes = array()   X-Ref
serialize an object

param: object  $object object to serialize
return: string  $string serialized data

_createXMLTag( $tag, $firstCall = true )   X-Ref
create a tag from an array
this method awaits an array in the following format
array(
'qname'        => $tagName,
'attributes'   => array(),
'content'      => $content,      // optional
'namespace'    => $namespace     // optional
'namespaceUri' => $namespaceUri  // optional
)

param: array   $tag tag definition
param: boolean $replaceEntities whether to replace XML entities in content or not
return: string  $string XML tag



Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics