ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTableDataParser.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
9{
10 protected $cdata = '';
11 protected $table = '';
12 protected $values = array();
13
19 public function setHandlers($a_xml_parser)
20 {
21 xml_set_object($a_xml_parser,$this);
22 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
23 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
24 }
25
29 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
30 {
31 switch($a_name)
32 {
33 case 'Table':
34 $this->table = $a_attribs['name'];
35 break;
36
37 case 'Row':
38 $this->values = array();
39 $this->num_values = -1;
40 break;
41
42 case 'Value':
43 $this->cdata = null;
44 $this->num_values++;
45 $this->values[$this->num_values]['name'] = $a_attribs['name'];
46 $this->values[$this->num_values]['type'] = $a_attribs['type'];
47 break;
48 }
49 }
50
54 function handlerEndTag($a_xml_parser, $a_name)
55 {
56 global $ilDB;
57
58 switch($a_name)
59 {
60 case 'Table':
61 break;
62
63 case 'Row':
64
65 $val = array();
66 foreach($this->values as $key => $data)
67 {
68 $val[$data['name']] = array($data['type'],$data['val']);
69 }
70 $ilDB->insert($this->table,$val);
71 break;
72
73 case 'Value':
74 $this->values[$this->num_values]['val'] = $this->cdata;
75 break;
76 }
77 }
78
79 function handlerCharacterData($a_xml_parser,$a_data)
80 {
81 if($this->cdata != null)
82 {
83 $this->cdata .= $a_data;
84 }
85 else
86 {
87 $this->cdata = $a_data;
88 }
89 }
90}
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
handlerCharacterData($a_xml_parser, $a_data)
handlerEndTag($a_xml_parser, $a_name)
handler for begin of element
$data
global $ilDB