ACC SHELL

Path : /srv/www/vhosts/ambfinance/admin/library/TF/
File Upload :
Current File : /srv/www/vhosts/ambfinance/admin/library/TF/XMLDoc.php

<?php
/**
 * Class to handle basic XML ops when DOMDocument not present
 *
 */
class TF_XMLDoc
{
    private $_doctype = null;
    private $_encoding = null;
    private $_rootNode = null;
    private $_rootNodeAttribs = array();
    private $_xml = null;
    private $_indent = "\t";
    /**
    * __construct
    */
    public function __construct($version = "1.0", $encoding = "UTF-8"){
        $this->_encoding = $encoding;
        $this->_doctype = '<'.'?xml version="'.$version.'" encoding="'.$encoding.'"?'.'>';
    } /* of __construct -------------------------------------*/

    /**
    * setRootNode
    */
    public function setRootNode($tag, $attributes = array()){
        if(is_null($this->_doctype)){
           throw new TF_Exception("Není definována XML hlavička!",500);
        }
        $this->_rootNode = $tag;
        $this->_rootNodeAttribs = $attributes;
    } /* of setRootNode -------------------------------------*/
    /**
    * appendXML
    */
    public function appendXML(TF_XMLTag $xml){
        if($xml instanceof TF_XMLTag){
            $this->_xml = str_ireplace("\r\n","\r\n".$this->_indent,$xml->__toString($this->_indent));
        } else {
            throw new TF_Exception("Toto není platné XML!",500);
        }
    } /* of appendXML -------------------------------------*/
    /**
    * getXMLDoc
    */
    public function getXMLDoc($echo = true,$header = true){
        if($header){
            header('Content-type: application/xml; charset="'.strtolower($this->_encoding).'"',true);
        }
        $res = $this->_doctype;
        foreach($this->_rootNodeAttribs as $key=>$val){
            $this->_rootNodeAttribs[$key] = '"'.htmlentities($val).'"';
        }
        $res .= '<'.$this->_rootNode.' '.implode("=",$this->_rootNodeAttribs).'>';
        $res .= $this->_xml;
        $res .= '</'.$this->_rootNode.'>';
        if($echo){
            echo $res;
            return true;
        } else {
            return $res;
        }
    } /* of getXMLDoc -------------------------------------*/
}

ACC SHELL 2018