Class XML_Serializer

Description

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.

Located in /PEAR/XML/Serializer.php (line 387)

PEAR
   |
   --XML_Serializer
Variable Summary
 array $options
Method Summary
 XML_Serializer XML_Serializer ([mixed $options = null])
 string apiVersion ()
 string getSerializedData ()
 void resetOptions ()
 boolean serialize (mixed $data, [mixed $options = null])
 void setOption (mixed $name, mixed $value)
 void setOptions (mixed $options)
 string _getDefaultTagname (string $parent)
Variables
array $options = array() (line 469)

options for the serialization

  • access: public
Methods
Constructor XML_Serializer (line 493)

constructor

  • access: public
XML_Serializer XML_Serializer ([mixed $options = null])
  • mixed $options: array containing options for the serialization
apiVersion (line 510)

return API version

  • return: API version
  • static:
  • access: public
string apiVersion ()
getSerializedData (line 650)

get the result of the serialization

  • return: serialized XML
  • access: public
string getSerializedData ()
resetOptions (line 521)

reset all options to default options

void resetOptions ()
serialize (line 559)

serialize data

  • return: true on success, pear error on failure
  • access: public
boolean serialize (mixed $data, [mixed $options = null])
  • mixed $data: data to serialize
setOption (line 534)

set an option

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

void setOption (mixed $name, mixed $value)
setOptions (line 547)

sets several options at once

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

void setOptions (mixed $options)
_getDefaultTagname (line 886)

get the name of the default tag.

The name of the parent tag needs to be passed as the default name can depend on the context.

  • return: default tag name
string _getDefaultTagname (string $parent)
  • string $parent: name of the parent tag

Inherited Methods

Inherited From PEAR

 PEAR::PEAR()
 PEAR::delExpect()
 PEAR::expectError()
 PEAR::getStaticProperty()
 PEAR::isError()
 PEAR::loadExtension()
 PEAR::popErrorHandling()
 PEAR::popExpect()
 PEAR::pushErrorHandling()
 PEAR::raiseError()
 PEAR::registerShutdownFunc()
 PEAR::setErrorHandling()
 PEAR::staticPopErrorHandling()
 PEAR::staticPushErrorHandling()
 PEAR::throwError()
 PEAR::_PEAR()

Documentation generated on Mon, 04 Dec 2006 11:10:08 -0500 by phpDocumentor 1.3.0RC3