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

Class: XML_Unserializer

Source Location: /XML_Serializer-0.15.0/Unserializer.php

Class Overview

PEAR
   |
   --XML_Unserializer

XML_Unserializer


Author(s):

Version:

  • 0.14.1

Methods


Inherited Variables

Inherited Methods


Class Details

[line 103]
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 ]


Method Detail

XML_Unserializer (Constructor)   [line 181]

XML_Unserializer XML_Unserializer( [mixed $options = null])

constructor
  • Access: public

Parameters:

mixed   $options     array containing options for the serialization

[ Top ]

apiVersion   [line 197]

string apiVersion( )

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

[ Top ]

getRootName   [line 325]

string getRootName( )

get the name of the root tag
  • Access: public

[ Top ]

getUnserializedData   [line 311]

string getUnserializedData( )

get the result of the serialization
  • Access: public

[ Top ]

resetOptions   [line 208]

void resetOptions( )

reset all options to default options

[ Top ]

setOption   [line 221]

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 234]

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 248]

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     string should be treated as a file
array   $options     

[ Top ]


Documentation generated on Sat, 12 Feb 2005 10:30:11 -0500 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.