Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?PHP
2
/**
3
 * Example to demonstrate the encodeFunction and decodeFunction
4
 * options.
5
 *
6
 * This allows you to apply callbacks to your data that is called
7
 * on all strings while serializing and unserializing.
8
 *
9
 * @author Stephan Schmidt <schst@php.net>
10
 */
11
    error_reporting(E_ALL);
12
 
13
    require_once 'XML/Serializer.php';
14
    require_once 'XML/Unserializer.php';
15
 
16
    $options = array(
17
                      XML_SERIALIZER_OPTION_INDENT               => '    ',
18
                      XML_SERIALIZER_OPTION_LINEBREAKS           => "\n",
19
                      XML_SERIALIZER_OPTION_SCALAR_AS_ATTRIBUTES => true,
20
                      XML_SERIALIZER_OPTION_ENCODE_FUNC          => 'strtoupper'
21
                    );
22
 
23
    $foo = new stdClass();
24
    $foo->bar = new stdClass();
25
    $foo->bar->test  = 'This is a test.';
26
    $foo->bar->value = 'This is a value.';
27
 
28
    $serializer = &new XML_Serializer($options);
29
 
30
    $result = $serializer->serialize($foo);
31
 
32
    if ($result === true) {
33
        $xml = $serializer->getSerializedData();
34
    }
35
 
36
    echo    "<pre>";
37
    print_r( htmlspecialchars($xml) );
38
    echo    "</pre>";
39
 
40
    $unserializer = &new XML_Unserializer();
41
    $unserializer->setOption('parseAttributes', true);
42
    $unserializer->setOption('decodeFunction', 'strtolower');
43
 
44
    $result = $unserializer->unserialize($xml);
45
 
46
    echo '<pre>';
47
    print_r($unserializer->getUnserializedData());
48
    echo '</pre>';
49
?>