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

Class: XML_Serializer

Source Location: /XML_Serializer-0.19.2/Serializer.php

Class Overview

PEAR
   |
   --XML_Serializer

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


Author(s):

Version:

  • Release: 0.19.2

Copyright:

  • 2003-2008 Stephan Schmidt <schst@php.net>

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 417]
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 562]

options for the serialization
  • Access: public

Type:   array


[ Top ]



Method Detail

XML_Serializer (Constructor)   [line 588]

void XML_Serializer( [mixed $options = null])

constructor
  • Access: public

Parameters:

mixed   $options     array containing options for the serialization

[ Top ]

apiVersion   [line 605]

string apiVersion( )

return API version
  • Return: API version
  • Access: public

[ Top ]

getSerializedData   [line 770]

string getSerializedData( )

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

[ Top ]

resetOptions   [line 617]

void resetOptions( )

reset all options to default options

[ Top ]

serialize   [line 666]

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

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

Parameters:

mixed   $data     data to serialize
array   $options     options array

[ Top ]

setOption   [line 635]

void setOption( string $name, mixed $value)

set an option

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


Parameters:

string   $name     option name
mixed   $value     option value

[ Top ]

setOptions   [line 652]

void setOptions( array $options)

sets several options at once

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


Parameters:

array   $options     options array

[ Top ]


Documentation generated on Sat, 24 Jan 2009 23:31:04 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.