﻿class XmlWriterWrapper {
    public function __construct() {
        $this->xml = new XmlWriter();
        $this->resStrBld = NULL;
    }
    public $xml;
    public $resStrBld;
    
    public static function CreateToFile($fname, $set = NULL) {
        $res = new XmlWriterWrapper();
        $res->xml->openUri($fname);
        if($set != NULL) $res->_settings($set);
        return $res;
    }
    public static function CreateToStringBuilder($sb, $set = NULL) {
        $res = new XmlWriterWrapper();
        $res->xml->openMemory();
        $res->resStrBld = $sb;
        if($set != NULL) $res->_settings($set);
        return $res;
    }
    function _settings($set) {
        $this->xml->setIndent($set->indent);
        $this->xml->setIndentString($set->indentChars);
    }

    public function Close() {
		if($this->xml == NULL) return;
        if($this->resStrBld != null) {
            $str = $this->xml->outputMemory();
            $this->resStrBld->Append($str);
        }
		else $this->xml->flush();
		$this->xml = NULL;
    }

}