2 // Copyright (C) 2011 Ensoftek
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
9 // This program is the base class to implement XML writer.
16 function __construct($indent = ' ')
18 $this->indent
= $indent;
19 $this->xml
= '<?xml version="1.0" encoding="utf-8"?>'."\n";
23 for ($i = 0, $j = count($this->stack
); $i < $j; $i++
) {
24 $this->xml
.= $this->indent
;
27 function push($element, $attributes = array())
30 $this->xml
.= '<'.$element;
31 foreach ($attributes as $key => $value) {
32 $this->xml
.= ' '.htmlspecialchars($key).'="'.htmlspecialchars($value).'"';
36 $this->stack
[] = htmlspecialchars($element);
38 function element($element, $content, $attributes = array())
41 $this->xml
.= '<'.$element;
42 foreach ($attributes as $key => $value) {
43 $this->xml
.= ' '.htmlspecialchars($key).'="'.htmlspecialchars($value).'"';
46 $this->xml
.= '>'.htmlspecialchars($content).'</'.htmlspecialchars($element).'>'."\n";
48 function emptyelement($element, $attributes = array())
51 $this->xml
.= '<'.htmlspecialchars($element);
52 foreach ($attributes as $key => $value) {
53 $this->xml
.= ' '.htmlspecialchars($key).'="'.htmlspecialchars($value).'"';
56 $this->xml
.= " />\n";
60 $element = array_pop($this->stack
);
62 $this->xml
.= "</".htmlspecialchars($element).">"."\n";