ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectXMLParser.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
34 include_once 'classes/class.ilSaxParser.php';
35 
37 {
38  var $object_data = array();
39 
49  function ilObjectXMLParser($a_xml_data = '', $throwException = false)
50  {
52  $this->setXMLContent($a_xml_data);
53  }
54 
55  function getObjectData()
56  {
57  return $this->object_data ? $this->object_data : array();
58  }
59 
66  function setHandlers($a_xml_parser)
67  {
68  xml_set_object($a_xml_parser,$this);
69  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
70  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
71  }
72 
73 
74 
75 
83  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
84  {
85  switch($a_name)
86  {
87  case 'Objects':
88  $this->curr_obj = -1;
89  break;
90 
91  case 'Object':
92  ++$this->curr_obj;
93 
94  $this->__addProperty('type',$a_attribs['type']);
95  $this->__addProperty('obj_id',is_numeric($a_attribs['obj_id'])?(int) $a_attribs["obj_id"] : ilUtil::__extractId($a_attribs["obj_id"], IL_INST_ID));
96  break;
97 
98  case 'Title':
99  break;
100 
101  case 'Description':
102  break;
103 
104  case 'Owner':
105  break;
106 
107  case 'CreateDate':
108  break;
109 
110  case 'LastUpdate':
111  break;
112 
113  case 'ImportId':
114  break;
115 
116  case 'References':
117  $this->ref_id = $a_attribs["ref_id"];
118  break;
119  }
120  }
121 
128  function handlerEndTag($a_xml_parser,$a_name)
129  {
130  switch($a_name)
131  {
132  case 'Objects':
133  break;
134 
135  case 'Object':
136  break;
137 
138  case 'Title':
139  $this->__addProperty('title',trim($this->cdata));
140  break;
141 
142  case 'Description':
143  $this->__addProperty('description',trim($this->cdata));
144  break;
145 
146  case 'Owner':
147  $this->__addProperty('owner',trim($this->cdata));
148  break;
149 
150  case 'CreateDate':
151  $this->__addProperty('create_date',trim($this->cdata));
152  break;
153 
154  case 'LastUpdate':
155  $this->__addProperty('last_update',trim($this->cdata));
156  break;
157 
158  case 'ImportId':
159  $this->__addProperty('import_id',trim($this->cdata));
160  break;
161 
162  case 'References':
163  $this->__addReference($this->ref_id);
164  break;
165  }
166 
167  $this->cdata = '';
168 
169  return;
170  }
171 
178  function handlerCharacterData($a_xml_parser,$a_data)
179  {
180  if($a_data != "\n")
181  {
182  // Replace multiple tabs with one space
183  $a_data = preg_replace("/\t+/"," ",$a_data);
184 
185  $this->cdata .= $a_data;
186  }
187 
188 
189  }
190 
191  // PRIVATE
192  function __addProperty($a_name,$a_value)
193  {
194  $this->object_data[$this->curr_obj][$a_name] = $a_value;
195  }
196 
197  function __addReference($a_value)
198  {
199  if($a_value)
200  {
201  $this->object_data[$this->curr_obj]['references'][] = $a_value;
202  }
203  }
204 
205 }
206 ?>