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

Class: XML_Unserializer

Source Location: /XML_Serializer-0.16.0/Unserializer.php

Class Overview

PEAR
   |
   --XML_Unserializer

XML_Unserializer


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 1997-2005 The PHP Group

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

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


1 require_once 'XML/Unserializer.php';
2
3 // be careful to always use the ampersand in front of the new operator
4 $unserializer = &new XML_Unserializer();
5
6 $unserializer->unserialize($xml);
7
8 $data = $unserializer->getUnserializedData();
9 <code>
10
11 Possible options for the Unserializer are:
12
13 1. complexTypes => array|object
14 This is needed, when unserializing XML files w/o type hints. If set to
15 'array' (default), all nested tags will be arrays, if set to 'object'
16 all nested tags will be objects, that means you have read access like:
17
18 <code>
19 require_once 'XML/Unserializer.php';
20 $options = array('complexType' => 'object');
21 $unserializer = &new XML_Unserializer($options);
22
23 $unserializer->unserialize('http://pear.php.net/rss.php');
24
25 $rss = $unserializer->getUnserializedData();
26 echo $rss->channel->item[3]->title;

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:


1 require_once 'XML/Unserializer.php';
2 $options = array('keyAttribute' => 'handle');
3 $unserializer = &new XML_Unserializer($options);
4
5 $unserializer->unserialize($xml, false);
6
7 $users = $unserializer->getUnserializedData();



[ Top ]


Class Variables

$options = array()

[line 146]

actual options for the serialization
  • Access: public

Type:   array


[ Top ]



Method Detail

XML_Unserializer (Constructor)   [line 202]

XML_Unserializer XML_Unserializer( [mixed $options = null])

constructor
  • Access: public

Parameters:

mixed   $options     array containing options for the unserialization

[ Top ]

apiVersion   [line 218]

string apiVersion( )

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

[ Top ]

getRootName   [line 345]

string getRootName( )

get the name of the root tag
  • Access: public

[ Top ]

getUnserializedData   [line 331]

string getUnserializedData( )

get the result of the serialization
  • Access: public

[ Top ]

resetOptions   [line 229]

void resetOptions( )

reset all options to default options

[ Top ]

setOption   [line 242]

void setOption( mixed $name, mixed $value)

set an option

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


[ Top ]

setOptions   [line 255]

void setOptions( mixed $options)

sets several options at once

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


[ Top ]

unserialize   [line 269]

boolean unserialize( mixed $data, [boolean $isFile = false], [array $options = null])

unserialize data
  • Access: public

Parameters:

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

[ Top ]


Documentation generated on Sun, 05 Jun 2005 09:30:11 -0400 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.