MkFramework
 All Data Structures Functions
plugin_xmlListObject.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
24 
25  private $tObject;
26  private $tColumn;
27  private $sEncoding;
28  private $sRootName;
29  private $sItemName;
30 
31  private $sXml;
32 
38  public function __construct($tObject){
39  $this->tObject=$tObject;
40 
41  $this->sEncoding='UTF-8';
42 
43  $this->sRootName='root';
44  $this->sItemName='item';
45  }
51  public function setEncoding($sEncoding){
52  $this->sEncoding=$sEncoding;
53  }
59  public function setRootName($sRootName){
60  $this->sRootName=$sRootName;
61  }
67  public function setItemName($sItemName){
68  $this->sItemName=$sItemName;
69  }
75  public function setListColumn($tColumn){
76  $this->tColumn=$tColumn;
77  }
82  public function show(){
83 
84  header ("Content-Type:text/xml");
85 
86  echo $this->build();
87 
88  exit;
89  }
95  public function build(){
96 
97  $this->sXml.='<?xml version="1.0" encoding="'.$this->sEncoding.'"?>';
98 
99  $this->open($this->sRootName);
100 
101  foreach($this->tObject as $oObject){
102 
103  $this->open($this->sItemName);
104 
105  foreach($this->tColumn as $sColumn){
106  $this->add($sColumn,$oObject->$sColumn);
107  }
108 
109  $this->close($this->sItemName);
110 
111  }
112  $this->close($this->sRootName);
113 
114  return $this->sXml;
115 
116  }
117 
118  private function add($sTag,$sValue){
119  $this->sXml.='<'.$sTag.'><![CDATA['.$sValue.']]></'.$sTag.'>';
120  }
121 
122  private function open($sTag){
123  $this->sXml.='<'.$sTag.'>';
124  }
125  private function close($sTag){
126  $this->sXml.='</'.$sTag.'>';
127  }
128 
129 }