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 example shows how to create an RDF document
4
 * with a few lines of code.
5
 * This can also be done with mode => simplexml
6
 *
7
 * @author Stephan Schmidt <schst@php.net>
8
 * @see    serializeIndexedArray.php
9
 */
10
error_reporting(E_ALL);
11
 
12
require_once 'XML/Serializer.php';
13
 
14
$options = array(
15
                    XML_SERIALIZER_OPTION_INDENT           => '    ',
16
                    XML_SERIALIZER_OPTION_LINEBREAKS       => "\n",
17
                    XML_SERIALIZER_OPTION_TYPEHINTS        => false,
18
                    XML_SERIALIZER_OPTION_XML_DECL_ENABLED => true,
19
                    XML_SERIALIZER_OPTION_XML_ENCODING     => 'UTF-8',
20
                    XML_SERIALIZER_OPTION_ROOT_NAME        => 'rdf:RDF',
21
                    XML_SERIALIZER_OPTION_ROOT_ATTRIBS     => array('version' => '0.91'),
22
                    XML_SERIALIZER_OPTION_DEFAULT_TAG      => 'item',
23
                    XML_SERIALIZER_OPTION_ATTRIBUTES_KEY   => '_attributes'
24
                );
25
 
26
$serializer = new XML_Serializer($options);
27
 
28
 
29
$rdf    =   array(
30
                    "channel" => array(
31
                                        "title" => "Example RDF channel",
32
                                        "link"  => "http://www.php-tools.de",
33
                                        "image"    =>    array(
34
                                                            "title"    => "Example image",
35
                                                            "url"    =>    "http://www.php-tools.de/image.gif",
36
                                                            "link"    =>    "http://www.php-tools.de"
37
                                                        ),
38
                                        "_attributes" => array( "rdf:about" => "http://example.com/foobar.html" ),
39
                                        array(
40
                                            "title"    => "Example item",
41
                                            "link"    => "http://example.com",
42
                                            "_attributes" => array( "rdf:about" => "http://example.com/foobar.html" )
43
                                        ),
44
                                        array(
45
                                            "title"    => "Another item",
46
                                            "link"    => "http://example.com",
47
                                            "_attributes" => array( "rdf:about" => "http://example.com/foobar.html" )
48
                                        ),
49
                                        array(
50
                                            "title"    => "I think you get it...",
51
                                            "link"    => "http://example.com",
52
                                            "_attributes" => array( "rdf:about" => "http://example.com/foobar.html" )
53
                                        )
54
                                    )
55
                );
56
 
57
$result = $serializer->serialize($rdf);
58
 
59
if ($result === true) {
60
    echo "<pre>";
61
    echo htmlentities($serializer->getSerializedData());
62
    echo "</pre>";
63
}
64
?>