2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
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. */
11 /************************************************************************/
15 * Class for parsing XML patch info (patch.xml)
23 var $parser; // the XML handler
24 var $patch_row = array(); // the patch data
25 var $character_data; // tmp variable for storing the data
26 var $element_path; // array of element paths (basically a stack)
28 var $action_detail_num;
29 var $dependent_patches_num;
31 function PatchParser() {
32 $this->parser = xml_parser_create('');
34 xml_set_object($this->parser, $this);
35 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
36 xml_set_element_handler($this->parser, 'startElement', 'endElement');
37 xml_set_character_data_handler($this->parser, 'characterData');
41 function parse($xml_data) {
42 $this->element_path = array();
43 $this->patch_row = array();
44 $this->character_data = '';
46 $this->action_detail_num = 0;
47 $this->dependent_patches_num = 0;
49 xml_parse($this->parser, $xml_data, TRUE);
53 function startElement($parser, $name, $attributes)
55 array_push($this->element_path, $name);
59 /* called when an element ends */
60 /* removed the current element from the $path */
61 function endElement($parser, $name)
63 if ($this->element_path == array('patch', 'system_patch_id'))
65 $this->patch_row['system_patch_id'] = trim($this->character_data);
67 if ($this->element_path == array('patch', 'applied_version'))
69 $this->patch_row['applied_version'] = trim($this->character_data);
71 if ($this->element_path == array('patch', 'sequence'))
73 $this->patch_row['sequence'] = trim($this->character_data);
75 if ($this->element_path == array('patch', 'description'))
77 $this->patch_row['description'] = trim($this->character_data);
79 if ($this->element_path === array('patch', 'dependent_patches', 'dependent_patch'))
81 $this->patch_row['dependent_patches'][$this->dependent_patches_num++] = trim($this->character_data);
83 if ($this->element_path == array('patch', 'sql'))
85 $this->patch_row['sql'] = trim($this->character_data);
87 else if ($this->element_path === array('patch', 'files', 'file', 'action'))
89 $this->patch_row['files'][$this->file_num]['action'] = trim($this->character_data);
91 else if ($this->element_path === array('patch', 'files', 'file', 'name'))
93 $this->patch_row['files'][$this->file_num]['name'] = trim($this->character_data);
95 else if ($this->element_path === array('patch', 'files', 'file', 'location'))
97 $this->patch_row['files'][$this->file_num]['location'] = trim($this->character_data);
99 else if ($this->element_path === array('patch', 'files', 'file', 'action_detail', 'type'))
101 $this->patch_row['files'][$this->file_num]['action_detail'][$this->action_detail_num]['type'] = trim($this->character_data);
103 else if ($this->element_path === array('patch', 'files', 'file', 'action_detail', 'code_from'))
105 $this->patch_row['files'][$this->file_num]['action_detail'][$this->action_detail_num]['code_from'] = trim($this->character_data);
107 else if ($this->element_path === array('patch', 'files', 'file', 'action_detail', 'code_to'))
109 $this->patch_row['files'][$this->file_num]['action_detail'][$this->action_detail_num]['code_to'] = trim($this->character_data);
111 else if ($this->element_path === array('patch', 'files', 'file'))
115 else if ($this->element_path === array('patch', 'files', 'file', 'action_detail'))
117 $this->action_detail_num++;
120 array_pop($this->element_path);
121 $this->character_data = '';
125 function characterData($parser, $data)
127 $this->character_data .= $data;
131 function getParsedArray()
133 return $this->patch_row;