2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /************************************************************************/
17 * Class for parsing XML module list info
20 * @package Admin Module
22 class ModuleListParser {
25 var $parser; // the XML handler
26 var $module_rows = array(); // the module data
27 var $character_data; // tmp variable for storing the data
28 var $element_path; // array of element paths (basically a stack)
32 function ModuleListParser() {
33 $this->parser = xml_parser_create('');
35 xml_set_object($this->parser, $this);
36 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
37 xml_set_element_handler($this->parser, 'startElement', 'endElement');
38 xml_set_character_data_handler($this->parser, 'characterData');
42 function parse($xml_data) {
43 $this->element_path = array();
44 $this->module_rows = array();
45 $this->character_data = '';
47 $this->history_num = 0;
48 xml_parse($this->parser, $xml_data, TRUE);
52 function startElement($parser, $name, $attributes)
54 array_push($this->element_path, $name);
58 /* called when an element ends */
59 /* removed the current element from the $path */
60 function endElement($parser, $name) {
61 if ($this->element_path == array('module_list', 'module', 'name'))
63 $this->module_rows[$this->row_num]['name'] = trim($this->character_data);
65 else if ($this->element_path === array('module_list', 'module', 'atutor_version'))
67 $this->module_rows[$this->row_num]['atutor_version'] = trim($this->character_data);
69 else if ($this->element_path === array('module_list', 'module', 'description'))
71 $this->module_rows[$this->row_num]['description'] = trim($this->character_data);
73 else if ($this->element_path === array('module_list', 'module', 'history'))
75 $this->history_num = 0;
77 else if ($this->element_path === array('module_list', 'module', 'history', 'release'))
81 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'version'))
83 $this->module_rows[$this->row_num]['history'][$this->history_num]['version'] = trim($this->character_data);
85 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'filename'))
87 $this->module_rows[$this->row_num]['history'][$this->history_num]['filename'] = trim($this->character_data);
89 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'location'))
91 $this->module_rows[$this->row_num]['history'][$this->history_num]['location'] = trim($this->character_data);
93 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'install_folder'))
95 $this->module_rows[$this->row_num]['history'][$this->history_num]['install_folder'] = trim($this->character_data);
97 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'date'))
99 $this->module_rows[$this->row_num]['history'][$this->history_num]['date'] = trim($this->character_data);
101 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'state'))
103 $this->module_rows[$this->row_num]['history'][$this->history_num]['state'] = trim($this->character_data);
105 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'maintainer'))
107 $this->module_rows[$this->row_num]['history'][$this->history_num]['maintainer'] = trim($this->character_data);
109 else if ($this->element_path === array('module_list', 'module', 'history', 'release', 'notes'))
111 $this->module_rows[$this->row_num]['history'][$this->history_num]['notes'] = trim($this->character_data);
113 else if ($this->element_path === array('module_list', 'module'))
118 array_pop($this->element_path);
119 $this->character_data = '';
123 function characterData($parser, $data){
124 $this->character_data .= $data;
128 function getNumOfModules()
130 return count($this->module_rows);
134 function getParsedArray()
136 return $this->module_rows;