indent = $indent; $this->breakLine = $breakLine; $this->xml = '' . "\n"; } private function indent () { for ($i = 0, $j = count($this->stack); $i < $j; $i++) $this->xml .= $this->indent; } public function push ($element, $attributes = array()) { $this->xml .= '<'. $element; foreach ($attributes as $key => $value) if (!is_numeric ($key)) $this->xml .= ($this->breakLine ? "\n" . $this->indent() : '') .' '. $key .'="'. $value .'"'; $this->xml .= ">\n"; $this->stack[] = $element; } public function element ($element, $content, $attributes = array()) { $this->xml .= '<'. $element; foreach ($attributes as $key => $value) if (!is_numeric ($key)) $this->xml .= ($this->breakLine ? "\n" . $this->indent() : '') .' '. $key .'="'. $value .'"'; $this->xml .= '>'. htmlentities ($content, ENT_QUOTES, 'UTF-8') .'' . "\n"; } public function emptyElement ($element, $attributes = array()) { $this->xml .= ($this->breakLine ? "\n" : '') . $this->indent() .'<'. $element; foreach ($attributes as $key => $value) if (!is_numeric ($key)) $this->xml .= ($this->breakLine ? "\n" . $this->indent() : '') .' '. $key .'="'. $value .'"'; $this->xml .= " />\n"; } public function collapseElement ($element, $attributes = array()) { $this->xml .= $this->indent()."<".$element; foreach ($attributes as $key => $value) if (!is_numeric ($key)) $this->xml .= ($this->breakLine ? "\n" . $this->indent() : '') .' '. $key .'="'. $value .'"'; $this->xml .= " />\n"; } public function pop () { $element = array_pop ($this->stack); $this->xml .= "\n"; } public function getXml () { return $this->xml; } } ?>