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

Class: XML_Serializer

Source Location: /XML_Serializer-0.20.2/XML/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:

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

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 428]
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 an RDF document from an array in the following format:
    1.     $data = array(
    2.         'channel' => array(
    3.             'title' => 'Example RDF channel',
    4.             'link'  => 'http://www.php-tools.de',
    5.             'image' => array(
    6.                 'title' => 'Example image',
    7.                 'url'   => 'http://www.php-tools.de/image.gif',
    8.                 'link'  => 'http://www.php-tools.de'
    9.             ),
    10.             array(
    11.                 'title' => 'Example item',
    12.                 'link'  => 'http://example.com'
    13.             ),
    14.             array(
    15.                 'title' => 'Another Example item',
    16.                 'link'  => 'http://example.org'
    17.             )
    18.         )
    19.     );
To create an RDF document from this array, do the following:

  1.     require_once 'XML/Serializer.php';
  2.     $options = array(
  3.        XML_SERIALIZER_OPTION_INDENT      => "\t",     // indent with tabs
  4.        XML_SERIALIZER_OPTION_LINEBREAKS  => "\n",     // use UNIX line breaks
  5.        XML_SERIALIZER_OPTION_ROOT_NAME   => 'rdf:RDF',// root tag
  6.        XML_SERIALIZER_OPTION_DEFAULT_TAG => 'item'    // tag for values
  7.                                                       // with numeric keys
  8.     );
  9.     $serializer = new XML_Serializer($options);
  10.     $rdf        $serializer->serialize($data);

You will get a complete XML document that can be processed like any RDF document.

2. This class 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 meta 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

  1.       XML_SERIALIZER_OPTION_TYPEHINTS => true
to the options array in the constructor.



[ Top ]


Class Variables

$options = array()

[line 576]

Options for the serialization
  • Access: public

Type:   array


[ Top ]



Method Detail

XML_Serializer (Constructor)   [line 601]

XML_Serializer XML_Serializer( [mixed $options = null])

Constructor
  • Access: public

Parameters:

mixed   $options   —  array containing options for the serialization

[ Top ]

apiVersion   [line 618]

string apiVersion( )

Return the package version number
  • Return: the version number of XML_Serializer
  • Access: public

[ Top ]

getSerializedData   [line 795]

string getSerializedData( )

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

[ Top ]

resetOptions   [line 629]

void resetOptions( )

Reset all options to default options
  • Access: public

[ Top ]

serialize   [line 679]

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

serialize data
  • Return: true on success, pear error on failure
  • Access: public
  • Uses: XML_Util::getXMLDeclaration()
  • Uses: XML_Util::getDoctypeDeclaration()

Parameters:

mixed   $data   —  data to serialize
array   $options   —  options array

[ Top ]

setOption   [line 646]

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.

  • Access: public

Parameters:

string   $name   —  option name
mixed   $value   —  option value

[ Top ]

setOptions   [line 662]

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.

  • Access: public

Parameters:

array   $options   —  options array

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:41:41 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.