Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?PHP
2
/**
3
 * XML Serializer example
4
 *
5
 * This example demonstrates, how XML_Serializer is able
6
 * to serialize scalar values as an attribute instead of a nested tag.
7
 *
8
 * In this example tags with more than one attribute become
9
 * multiline tags, as each attribute gets written to a
10
 * separate line as 'indentAttributes' is set to '_auto'.
11
 *
12
 * @author  Stephan Schmidt <schst@php.net>
13
 */
14
    error_reporting(E_ALL);
15
    require_once 'XML/Serializer.php';
16
 
17
    $options = array(
18
                        "indent"             => "    ",
19
                        "linebreak"          => "\n",
20
                        "typeHints"          => false,
21
                        "defaultTagName"     => "unnamedItem",
22
                        "scalarAsAttributes" => true,
23
                        "indentAttributes"   => "_auto"
24
                    );
25
 
26
    // this is just to get a nested object
27
    $pearError = PEAR::raiseError('This is just an error object',123);
28
 
29
    $foo    =   new stdClass;
30
 
31
    $foo->value = "My value";
32
    $foo->error = $pearError;
33
    $foo->xml   = "cool";
34
 
35
    $serializer = new XML_Serializer($options);
36
 
37
    $result = $serializer->serialize($foo);
38
 
39
    if( $result === true ) {
40
        $xml = $serializer->getSerializedData();
41
 
42
        echo    "<pre>";
43
        print_r( htmlspecialchars($xml) );
44
        echo    "</pre>";
45
    } else {
46
        echo    "<pre>";
47
        print_r($result);
48
        echo    "</pre>";
49
    }
50
 
51
?>