Location: PHPKode > scripts > XML-Writer > XMLFile.php
class XMLFile  
{
  private $fd = 0;
  
  function __destruct()
  {
    $this->close();
  }
  
  public function open($name)
  {
    $this->fd = fopen($name,'w');
  }
  
  public function forceopen($name)
  {
    $this->fd = fopen($name,'w+');
  }
  public function close()
  {
    if ($this->fd)
    {
      fclose($this->fd);
      $this->fd = 0;
    }
  }
  

  
  public function writeText(&$text)
  {
    fwrite($this->fd, htmlspecialchars($text));
  }
  
  public function writeOpenTag($tagname,$attrs='')
  {
    if (strlen($attrs)) $attrs = " $attrs "; 
    fwrite($this->fd, "<$tagname$attrs>\n");
  }
  
  public function writeElement($tagname, $attrs='', $value='')
  {
    if (strlen($attrs)) $attrs = " $attrs "; 
    if (strlen($value))
    {
      fwrite($this->fd, "<$tagname$attrs>".htmlspecialchars($value)."</$tagname>\n");
    }
    else
    {
      fwrite($this->fd, "<$tagname$attrs/>\n");
    }
  }
  
  

  
  public function writeArray($arr, $rootName)
  {
       if ($rootName != ""){
        $root = $rootName;
        }else{
         $root = "root";
        }
  
      if (!is_array($arr) && count($arr) == 0) { return false;}  /// array vuoto
  
				fwrite($this->fd, "<$rootName>\n");
  
					foreach ($arr as $key => $val){  /// funzione ricursiva per explodere gli array

					    if (is_array($val)) {
                   $this->writeArray($val,$key);
              }else{ 
					         fwrite($this->fd, "<$key>".htmlspecialchars($val)."</$key>\n");
              }
					}
			  fwrite($this->fd, "</$rootName>\n");

    
  }
  
  public function writeWord($tagname)
  {
    fwrite($this->fd, "$tagname\n");
  }
  
  public function writeCloseTag($tagname)
  {
    fwrite($this->fd, "</$tagname>\n");
  }
  
  
  public function writeHeader()
  {
    fwrite($this->fd, '<?xml version="1.0" encoding="ISO-8859-1"?>');
    fwrite($this->fd, "\n");
  }
  
  
};
Return current item: XML-Writer