<?php

/**
 * Description of XmlClass
 *
 * @author Fabio
 */
class Xml {
    //put your code here
    private $xml;
    private $tab = 1;

  public function __construct($version = '1.0', $encoding = 'UTF-8') {
	//public function __construct($version = '1.0', $encoding = 'ISO-8859-1') {
        $this->xml .= "<?xml version='$version' encoding='$encoding'?>\n";;
    }

    public function openTag($name){
        $this->addTab();
        $this->xml .= "<$name>\n";
        $this->tab++;
    }

    public function closeTag($name){
        $this->tab--;
        $this->addTab();
        $this->xml .= "</$name>\n";
    }

    public function addTag($name, $value){
        $this->addTab();
        $this->xml .= "<$name>$value</$name>\n";
    }

    private function addTab(){
        for ($i = 1; $i <= $this->tab; $i++){
            $this->xml .= "\t";
        }
    }

    public function __toString() {
        return $this->xml;
    }
}
?>
