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

Class: XML_Serializer

Source Location: /XML_Serializer-0.2/Serializer.php

Class Overview

PEAR
   |
   --XML_Serializer

XML_Serializer class that serializes various structures into an XML document


Author(s):

Version:

  • 0.2b

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 112]
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 "tagName" => "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.

Finally a list of all possible options that can be set in the constructor:

array( "indent" => "\t", // string used for indentation "linebreak" => "\n", // string used for linebreaks "defaultTagName" => "myName", // tagname for unnamed values (indexed array) "addDecl" => true, // add XML declaration "encoding" => "UTF-8", // encoding specified in XML declaration "typeHints" => true // add '_type' and '_class' attributes to the tags )

  • Todo: check tagnames with XML_Util::isValidName()
  • Todo: namespace support
  • Todo: specify custom rules for the serialization, so that values can be stored in attributes instead of tags
  • Todo: unserialize() method
  • Todo: better serialization of objects (__sleep, custom methods)
  • Author: Stephan Schmidt <mailto:schst@php-tools.de>
  • Uses: XML_Util
  • Version: 0.2b


[ Top ]


Class Variables

$options = array(
                         "indent"         => "",
                         "linebreak"      => "",
                         "typeHints"      => false,
                         "addDecl"        => false,
                         "defaultTagName" => "XML_Serializer_Tag"
                        )

[line 118]

default options for the serialization

Type:   array


[ Top ]



Method Detail

XML_Serializer (Constructor)   [line 143]

XML_Serializer XML_Serializer( [mixed $options = null])

constructor
  • Access: public

Parameters:

mixed   $options     array containing options for the serialization

[ Top ]

apiVersion   [line 158]

string apiVersion( )

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

[ Top ]

getSerializedData   [line 225]

string getSerializedData( )

get the result of the serialization
  • Access: public

[ Top ]

serialize   [line 170]

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

serialize data
  • Return: serialized data
  • Access: public

Parameters:

mixed   $data     data to serialize

[ Top ]


Documentation generated on Sat, 1 May 2004 00:13:41 +0200 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.