Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?PHP
2
/**
3
 * This is just a basic example that shows
4
 * how objects can be serialized so they can
5
 * be fully restored later.
6
 *
7
 * @author Stephan Schmidt <schst@php.net>
8
 */
9
error_reporting(E_ALL);
10
 
11
require_once 'XML/Serializer.php';
12
 
13
$options = array(
14
                    XML_SERIALIZER_OPTION_INDENT      => '    ',
15
                    XML_SERIALIZER_OPTION_LINEBREAKS  => "\n",
16
                    XML_SERIALIZER_OPTION_COMMENT_KEY => 'comment'
17
                );
18
 
19
$foo = new stdClass;
20
$foo->comment = 'This is a comment';
21
$foo->value   = 'My value';
22
 
23
$foo->bar     = new stdClass();
24
$foo->bar->value   = 'Another value';
25
$foo->bar->comment = 'Another comment';
26
 
27
$foo->tomato          = new stdClass();
28
$foo->tomato->comment = 'And a last comment';
29
 
30
$serializer = &new XML_Serializer($options);
31
 
32
$result = $serializer->serialize($foo);
33
 
34
if ($result === true) {
35
    $xml = $serializer->getSerializedData();
36
}
37
 
38
echo '<pre>';
39
echo htmlspecialchars($xml);
40
echo '</pre>';
41
?>