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

Class: XML_Serializer

Source Location: /XML_Serializer-0.11.0/Serializer.php

Class Overview

PEAR
   |
   --XML_Serializer

XML_Serializer class that serializes various structures into an XML document


Author(s):

Version:

  • 0.9.1

Methods


Inherited Variables

Inherited Methods


Class Details

[line 103]
XML_Serializer class that serializes various structures into an XML document

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( 'indent' => "\t", // indent with tabs 'linebreak' => "\n", // use UNIX line breaks 'rootName' => 'rdf:RDF', // root tag 'defaultTagName' => '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

'typeHints' => true

to the options array in the constructor.

Future versions of this package will include an XML_Unserializer, that does the unserialization automatically for you.



[ Top ]


Method Detail

XML_Serializer (Constructor)   [line 157]

XML_Serializer XML_Serializer( [mixed $options = null])

constructor
  • Access: public

Parameters:

mixed   $options     array containing options for the serialization

[ Top ]

apiVersion   [line 174]

string apiVersion( )

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

[ Top ]

getSerializedData   [line 302]

string getSerializedData( )

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

[ Top ]

resetOptions   [line 185]

void resetOptions( )

reset all options to default options

[ Top ]

serialize   [line 223]

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 198]

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 211]

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 Tue, 24 Aug 2004 09:40:06 -0400 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.