XML_Serializer
[ class tree: XML_Serializer ] [ index: XML_Serializer ] [ all elements ]

Class: XML_Serializer

Source Location: /XML_Serializer-0.18.0/Serializer.php

Class Overview

PEAR
   |
   --XML_Serializer

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


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 1997-2005 The PHP Group

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 387]
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.



[ Top ]


Class Variables

$options = array()

[line 469]

options for the serialization
  • Access: public

Type:   array


[ Top ]



Method Detail

XML_Serializer (Constructor)   [line 493]

XML_Serializer XML_Serializer( [mixed $options = null])

constructor
  • Access: public

Parameters:

mixed   $options     array containing options for the serialization

[ Top ]

apiVersion   [line 510]

string apiVersion( )

return API version
  • Return: API version
  • Static: This method can be called statically
  • Access: public

[ Top ]

getSerializedData   [line 650]

string getSerializedData( )

get the result of the serialization
  • Return: serialized XML
  • Access: public

[ Top ]

resetOptions   [line 521]

void resetOptions( )

reset all options to default options

[ Top ]

serialize   [line 559]

boolean serialize( mixed $data, [mixed $options = null])

serialize data
  • Return: true on success, pear error on failure
  • Access: public

Parameters:

mixed   $data     data to serialize

[ Top ]

setOption   [line 534]

void setOption( mixed $name, mixed $value)

set an option

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


[ Top ]

setOptions   [line 547]

void setOptions( mixed $options)

sets several options at once

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


[ Top ]


Documentation generated on Sun, 02 Oct 2005 14:00:13 -0400 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.