3 // Copyright (C) 2011 Ensoftek
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is the base class to implement XML writer.
17 function __construct($indent = ' ')
19 $this->indent
= $indent;
20 $this->xml
= '<?xml version="1.0" encoding="utf-8"?>' . "\n";
24 for ($i = 0, $j = count($this->stack
); $i < $j; $i++
) {
25 $this->xml
.= $this->indent
;
28 function push($element, $attributes = array())
31 $this->xml
.= '<' . $element;
32 foreach ($attributes as $key => $value) {
33 $this->xml
.= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
37 $this->stack
[] = htmlspecialchars($element);
39 function element($element, $content, $attributes = array())
42 $this->xml
.= '<' . $element;
43 foreach ($attributes as $key => $value) {
44 $this->xml
.= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
47 $this->xml
.= '>' . htmlspecialchars($content) . '</' . htmlspecialchars($element) . '>' . "\n";
49 function emptyelement($element, $attributes = array())
52 $this->xml
.= '<' . htmlspecialchars($element);
53 foreach ($attributes as $key => $value) {
54 $this->xml
.= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
57 $this->xml
.= " />\n";
61 $element = array_pop($this->stack
);
63 $this->xml
.= "</" . htmlspecialchars($element) . ">" . "\n";