[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libs/Xml/ -> Unserializer.php (sommaire)

XML_Unserializer Parses any XML document into PHP data structures.

Author: Stephan Schmidt <schst@php.net>
Copyright: 1997-2005 The PHP Group
License: http://www.php.net/license/3_0.txt PHP License 3.0
Version: CVS: $Id: Unserializer.php,v 1.1 2005/12/06 01:50:39 matthieu_ Exp $
Poids: 578 lignes (19 kb)
Inclus ou requis: 1 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 1 class

XML_Unserializer:: (12 méthodes):
  XML_Unserializer()
  apiVersion()
  resetOptions()
  setOption()
  setOptions()
  unserialize()
  getUnserializedData()
  getRootName()
  startHandler()
  endHandler()
  cdataHandler()
  _createParser()


Classe: XML_Unserializer  - X-Ref

XML_Unserializer

class to unserialize XML documents that have been created with
XML_Serializer. To unserialize an XML document you have to add
type hints to the XML_Serializer options.

If no type hints are available, XML_Unserializer will guess how
the tags should be treated, that means complex structures will be
arrays and tags with only CData in them will be strings.

<code>
require_once 'XML/Unserializer.php';

//  be careful to always use the ampersand in front of the new operator
$unserializer = &new XML_Unserializer();

$unserializer->unserialize($xml);

$data = $unserializer->getUnserializedData();
<code>

Possible options for the Unserializer are:

1. complexTypes => array|object
This is needed, when unserializing XML files w/o type hints. If set to
'array' (default), all nested tags will be arrays, if set to 'object'
all nested tags will be objects, that means you have read access like:

<code>
require_once 'XML/Unserializer.php';
$options = array('complexType' => 'object');
$unserializer = &new XML_Unserializer($options);

$unserializer->unserialize('http://pear.php.net/rss.php');

$rss = $unserializer->getUnserializedData();
echo $rss->channel->item[3]->title;
</code>

2. keyAttribute
This lets you specify an attribute inside your tags, that are used as key
for associative arrays or object properties.
You will need this if you have XML that looks like this:

<users>
<user handle="schst">Stephan Schmidt</user>
<user handle="ssb">Stig S. Bakken</user>
</users>

Then you can use:
<code>
require_once 'XML/Unserializer.php';
$options = array('keyAttribute' => 'handle');
$unserializer = &new XML_Unserializer($options);

$unserializer->unserialize($xml, false);

$users = $unserializer->getUnserializedData();
</code>

XML_Unserializer($options = null)   X-Ref
constructor

param: mixed   $options    array containing options for the unserialization

apiVersion()   X-Ref
return API version

return: string  $version API version

resetOptions()   X-Ref
reset all options to default options


setOption($name, $value)   X-Ref
set an option

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


setOptions($options)   X-Ref
sets several options at once

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


unserialize($data, $isFile = false, $options = null)   X-Ref
unserialize data

param: mixed    $data     data to unserialize (string, filename or resource)
param: boolean  $isFile   data should be treated as a file
param: array    $options  options that will override the global options for this call
return: boolean  $success

getUnserializedData()   X-Ref
get the result of the serialization

return: string  $serializedData

getRootName()   X-Ref
get the name of the root tag

return: string  $rootName

startHandler($parser, $element, $attribs)   X-Ref
Start element handler for XML parser

param: object $parser  XML parser object
param: string $element XML element
param: array  $attribs attributes of XML tag
return: void

endHandler($parser, $element)   X-Ref
End element handler for XML parser

param: object XML parser object
param: string
return: void

cdataHandler($parser, $cdata)   X-Ref
Handler for character data

param: object XML parser object
param: string CDATA
return: void

_createParser()   X-Ref
create the XML_Parser instance

return: boolean



Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics