PHP Classes

File: SXMC

Recommend this page to a friend!
  Packages of lazy   Create A Simple XML FIle   SXMC   Download  
File: SXMC
Role: Class source
Content type: text/plain
Description: A Simple Class To Create A Simple XML File.
Class: Create A Simple XML FIle
A Simple Class To Create A Simple XML File.
Author: By
Last change: New Version
Date: 19 years ago
Size: 2,426 bytes
 

 

Contents

Class file image Download
<?php
/**
 * A Simple XML Make Class(SXMC)
 * Version:0.3 Beta
 * Author :Lazy
 * E-mail :o0lazy0o at gmail dot com
 * Welcome To http://www.52radio.net/
 * Copyright:None.
 */
Class XML{
    var $Content="";
    var $RootNode="";
    var $ParentNode="";
    var $CRLF="\r\n";
    var $End="";
    
    Function XML($Version="1.0",$Encoding="utf-8"){
        $this->Content.="<?xml version=\"{$Version}\" encoding=\"{$Encoding}\"?>{$this->CRLF}";
    }

    Function CreateNode($NodeName="root",$Attribute=""){
        $NodeName=$this->Filter($NodeName);
        $this->RootNode=$NodeName;
        $Attribute=$this->ParseAttribute($Attribute);
        return $this->Content.="<{$NodeName}{$Attribute}>{$this->CRLF}";
    }

    Function AppendNode($NodeName,$Attribute,$Data="",$CDate=true){
        $NodeName=$this->Filter($NodeName);
        if(empty($Data)){
            if(!empty($this->ParentNode)){
                $this->Content.="</{$this->ParentNode}>{$this->CRLF}";
            }
            $this->ParentNode=$NodeName;
            $Attribute=$this->ParseAttribute($Attribute);
            return $this->Content.="<{$NodeName}{$Attribute}>{$this->CRLF}";
        }else{
            $Attribute=$this->ParseAttribute($Attribute);
            return $this->Content.=$CDate?"<{$NodeName}{$Attribute}>{$this->CRLF}<![CDATA[{$Data}]]>{$this->CRLF}</{$NodeName}>{$this->CRLF}":"<{$NodeName}{$Attribute}>{$Data}</{$NodeName}>{$this->CRLF}";
        }
    }
    
    Function End(){
        if($this->End){
            return $this->Content;
        }else{
            $this->End=true;
            return $this->Content=$this->ParentNode==""?$this->Content."</{$this->RootNode}>":$this->Content."</{$this->ParentNode}>{$this->CRLF}</{$this->RootNode}>";
        }
    }

    Function Display(){
        ob_start();
        header("Content-type: text/xml");
        echo $this->End();
        ob_end_flush();
    }

    Function Save($Filename){
        if(!$Handle=fopen($Filename,'wb+')){
            $this->Error("Couldn't Write File,Make Sure Your Access");
        }
        flock($Handle,LOCK_EX);
        fwrite($Handle,$this->End());
        return fclose($Handle);
    }

    Function Error($ErrorStr='',$ErrorNo='',$Stop=true){
        exit($ErrorStr);
    }

    Function ParseAttribute($Argv){
        $Attribute='';
        if(is_array($Argv)){
            foreach($Argv as $Key=>$Value){
                $Value=$this->Filter($Value);
                $Attribute.=" $Key=\"$Value\"";
            }
        }
        return $Attribute;
    }
    
    Function Filter($Argv){
        $Argv=trim($Argv);
        $Search=array("<",">","\"");
        $Replace=array("","","'");
        return str_replace($Search,$Replace,$Argv);
    }
}
?>