2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto */
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 /************************************************************************/
13 // $Id: PatchParser.class.php 7208 2008-02-08 16:07:24Z greg $
17 * Class for parsing XML patch info (patch.xml)
25 var $parser; // the XML handler
26 var $patch_row = array(); // the patch data
27 var $character_data; // tmp variable for storing the data
28 var $element_path; // array of element paths (basically a stack)
30 var $action_detail_num;
31 var $dependent_patches_num;
33 function PatchParser() {
34 $this->parser = xml_parser_create('');
36 xml_set_object($this->parser, $this);
37 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
38 xml_set_element_handler($this->parser, 'startElement', 'endElement');
39 xml_set_character_data_handler($this->parser, 'characterData');
43 function parse($xml_data) {
44 $this->element_path = array();
45 $this->patch_row = array();
46 $this->character_data = '';
48 $this->action_detail_num = 0;
49 $this->dependent_patches_num = 0;
51 xml_parse($this->parser, $xml_data, TRUE);
55 function startElement($parser, $name, $attributes)
57 array_push($this->element_path, $name);
61 /* called when an element ends */
62 /* removed the current element from the $path */
63 function endElement($parser, $name)
65 if ($this->element_path == array('patch', 'atutor_patch_id'))
67 $this->patch_row['atutor_patch_id'] = trim($this->character_data);
69 if ($this->element_path == array('patch', 'applied_version'))
71 $this->patch_row['applied_version'] = trim($this->character_data);
73 if ($this->element_path == array('patch', 'sequence'))
75 $this->patch_row['sequence'] = trim($this->character_data);
77 if ($this->element_path == array('patch', 'description'))
79 $this->patch_row['description'] = trim($this->character_data);
81 if ($this->element_path === array('patch', 'dependent_patches', 'dependent_patch'))
83 $this->patch_row['dependent_patches'][$this->dependent_patches_num++] = trim($this->character_data);
85 if ($this->element_path == array('patch', 'sql'))
87 $this->patch_row['sql'] = trim($this->character_data);
89 else if ($this->element_path === array('patch', 'files', 'file', 'action'))
91 $this->patch_row['files'][$this->file_num]['action'] = trim($this->character_data);
93 else if ($this->element_path === array('patch', 'files', 'file', 'name'))
95 $this->patch_row['files'][$this->file_num]['name'] = trim($this->character_data);
97 else if ($this->element_path === array('patch', 'files', 'file', 'location'))
99 $this->patch_row['files'][$this->file_num]['location'] = trim($this->character_data);
101 else if ($this->element_path === array('patch', 'files', 'file', 'action_detail', 'type'))
103 $this->patch_row['files'][$this->file_num]['action_detail'][$this->action_detail_num]['type'] = trim($this->character_data);
105 else if ($this->element_path === array('patch', 'files', 'file', 'action_detail', 'code_from'))
107 $this->patch_row['files'][$this->file_num]['action_detail'][$this->action_detail_num]['code_from'] = trim($this->character_data);
109 else if ($this->element_path === array('patch', 'files', 'file', 'action_detail', 'code_to'))
111 $this->patch_row['files'][$this->file_num]['action_detail'][$this->action_detail_num]['code_to'] = trim($this->character_data);
113 else if ($this->element_path === array('patch', 'files', 'file'))
117 else if ($this->element_path === array('patch', 'files', 'file', 'action_detail'))
119 $this->action_detail_num++;
122 array_pop($this->element_path);
123 $this->character_data = '';
127 function characterData($parser, $data)
129 $this->character_data .= $data;
133 function getParsedArray()
135 return $this->patch_row;