File: DumpXmlTest.php

package info (click to toggle)
php-horde-rdo 2.1.0-10
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 472 kB
  • sloc: php: 1,610; xml: 428; sql: 100; sh: 3; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 942 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
 * @package Rdo
 */

require_once './Clotho.php';

class XmlItemMapper extends ItemMapper
{
}

class XmlItem extends Item
{
    /**
     * Return an XML representation of this object. The default
     * implementation is unlikely to be useful in most cases and
     * should be overridden by subclasses to be domain-appropriate.
     *
     * @TODO: see http://pear.php.net/pepr/pepr-proposal-show.php?id=361 ?
     *
     * @return string XML representation of $this.
     */
    public function toXml()
    {
        $doc = new DOMDocument('1.0');

        $root = $doc->appendChild($doc->createElement(get_class($this)));
        foreach ($this as $field => $value) {
            $f = $root->appendChild($doc->createElement($field));
            $f->appendChild($doc->createTextNode($value));
        }

        return $doc->saveXML();
    }
}

$im = new XmlItemMapper($conf['adapter']);

$i = $im->findOne(1);
echo $i->toXml();