1<?php
2
3
4
5  /*
6   +-----------------------------------------------------------------------------+
7   | ILIAS open source                                                           |
8   +-----------------------------------------------------------------------------+
9   | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
10   |                                                                             |
11   | This program is free software; you can redistribute it and/or               |
12   | modify it under the terms of the GNU General Public License                 |
13   | as published by the Free Software Foundation; either version 2              |
14   | of the License, or (at your option) any later version.                      |
15   |                                                                             |
16   | This program is distributed in the hope that it will be useful,             |
17   | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
18   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
19   | GNU General Public License for more details.                                |
20   |                                                                             |
21   | You should have received a copy of the GNU General Public License           |
22   | along with this program; if not, write to the Free Software                 |
23   | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
24   +-----------------------------------------------------------------------------+
25  */
26
27
28 /**
29   * Parser for XMLResultSet
30   *
31   * @author Roland Kuestermann (rku@aifb.uni-karlsruhe.de)
32   * @version $Id: class.ilXMLResultSet.php,v 1.5 2006/05/23 23:09:06 hschottm Exp $
33   *
34   * @package ilias
35   */
36
37include_once './Services/Xml/classes/class.ilSaxParser.php';
38include_once './webservice/soap/classes/class.ilXMLResultSet.php';
39
40class ilXMLResultSetParser extends ilSaxParser
41{
42    public $xmlResultSet;
43
44    /**
45    * Constructor
46    * @param	string		$a_xml_data			xml data
47    * @access	public
48    */
49    public function __construct($a_xml_data = '')
50    {
51        parent::__construct();
52        $this->setXMLContent($a_xml_data);
53    }
54
55    /**
56     * parsed result
57     *
58     * @return ilXMLResultSet xmlResultSet
59     */
60    public function getXMLResultSet()
61    {
62        return $this->xmlResultSet;
63    }
64
65    /**
66    * set event handlers
67    *
68    * @param	resource	reference to the xml parser
69    * @access	private
70    */
71    public function setHandlers($a_xml_parser)
72    {
73        xml_set_object($a_xml_parser, $this);
74        xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
75        xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
76    }
77
78
79    /**
80    * handler for begin of element
81    *
82    * @param	resource	$a_xml_parser		xml parser
83    * @param	string		$a_name				element name
84    * @param	array		$a_attribs			element attributes array
85    */
86    public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
87    {
88        switch ($a_name) {
89            case 'result':
90                $this->xmlResultSet = new ilXMLResultSet();
91                break;
92
93            case 'colspecs':
94                break;
95
96            case 'colspec':
97                $this->xmlResultSet->addColumn($a_attribs["name"]);
98                break;
99            case 'row':
100                $this->currentRow = new ilXMLResultSetRow();
101                $this->xmlResultSet->addRow($this->currentRow);
102                $this->currentColumnIndex = 0;
103                break;
104            case 'column':
105                break;
106        }
107    }
108
109    /**
110    * handler for end of element
111    *
112    * @param	resource	$a_xml_parser		xml parser
113    * @param	string		$a_name				element name
114    */
115    public function handlerEndTag($a_xml_parser, $a_name)
116    {
117        switch ($a_name) {
118            case 'column':
119                $this->currentRow->setValue($this->currentColumnIndex, $this->cdata);
120                $this->currentColumnIndex++;
121                break;
122        }
123        $this->cdata = '';
124    }
125
126    /**
127    * handler for character data
128    *
129    * @param	resource	$a_xml_parser		xml parser
130    * @param	string		$a_data				character data
131    */
132    public function handlerCharacterData($a_xml_parser, $a_data)
133    {
134        if ($a_data != "\n") {
135            // Replace multiple tabs with one space
136            $a_data = preg_replace("/\t+/", " ", $a_data);
137
138            $this->cdata .= trim($a_data);
139        }
140    }
141}
142