Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_XMLParser Class Reference
Inheritance diagram for PEAR_XMLParser:

Public Member Functions

 cdataHandler ($parser, $cdata)
 endHandler ($parser, $element)
 getData ()
 parse ($data)
 postProcess ($data, $element)
 startHandler ($parser, $element, $attribs)

Data Fields

 $_dataStack = array()
 $_depth = 0
 $_root = null
 $_unserializedData = null
 $_valStack = array()
 $encoding = 'ISO-8859-1'

Detailed Description

Definition at line 29 of file XMLParser.php.

Member Function Documentation

◆ cdataHandler()

cdataHandler ( $parser,
$cdata )

Handler for character data

@access private

Parameters
objectXML parser object
stringCDATA
Returns
void

Definition at line 243 of file XMLParser.php.

244 {
245 $this->_dataStack[$this->_depth] .= $cdata;
246 }

References $_depth.

◆ endHandler()

endHandler ( $parser,
$element )

End element handler for XML parser

@access private

Parameters
objectXML parser object
string
Returns
void

Definition at line 163 of file XMLParser.php.

164 {
165 $value = array_pop($this->_valStack);
166 $data = $this->postProcess($this->_dataStack[$this->_depth], $element);
167
168 // adjust type of the value
169 switch (strtolower($value['type'])) {
170 // unserialize an array
171 case 'array':
172 if ($data !== '') {
173 $value['children']['_content'] = $data;
174 }
175
176 $value['value'] = isset($value['children']) ? $value['children'] : array();
177 break;
178
179 /*
180 * unserialize a null value
181 */
182 case 'null':
183 $data = null;
184 break;
185
186 /*
187 * unserialize any scalar value
188 */
189 default:
190 settype($data, $value['type']);
191 $value['value'] = $data;
192 break;
193 }
194
195 $parent = array_pop($this->_valStack);
196 if ($parent === null) {
197 $this->_unserializedData = &$value['value'];
198 $this->_root = &$value['name'];
199 return true;
200 }
201
202 // parent has to be an array
203 if (!isset($parent['children']) || !is_array($parent['children'])) {
204 $parent['children'] = array();
205 if ($parent['type'] != 'array') {
206 $parent['type'] = 'array';
207 }
208 }
209
210 if (!empty($value['name'])) {
211 // there already has been a tag with this name
212 if (in_array($value['name'], $parent['childrenKeys'])) {
213 // no aggregate has been created for this tag
214 if (!in_array($value['name'], $parent['aggregKeys'])) {
215 if (isset($parent['children'][$value['name']])) {
216 $parent['children'][$value['name']] = array($parent['children'][$value['name']]);
217 } else {
218 $parent['children'][$value['name']] = array();
219 }
220 array_push($parent['aggregKeys'], $value['name']);
221 }
222 array_push($parent['children'][$value['name']], $value['value']);
223 } else {
224 $parent['children'][$value['name']] = &$value['value'];
225 array_push($parent['childrenKeys'], $value['name']);
226 }
227 } else {
228 array_push($parent['children'],$value['value']);
229 }
230 array_push($this->_valStack, $parent);
231
232 $this->_depth--;
233 }
postProcess($data, $element)

References postProcess().

Here is the call graph for this function:

◆ getData()

getData ( )
Returns
array

Definition at line 70 of file XMLParser.php.

71 {
73 }

References $_unserializedData.

◆ parse()

parse ( $data)
Parameters
stringxml content
Returns
true|PEAR_Error

Definition at line 79 of file XMLParser.php.

80 {
81 if (!extension_loaded('xml')) {
82 include_once 'PEAR.php';
83 return PEAR::raiseError("XML Extension not found", 1);
84 }
85 $this->_dataStack = $this->_valStack = array();
86 $this->_depth = 0;
87
88 if (
89 strpos($data, 'encoding="UTF-8"')
90 || strpos($data, 'encoding="utf-8"')
91 || strpos($data, "encoding='UTF-8'")
92 || strpos($data, "encoding='utf-8'")
93 ) {
94 $this->encoding = 'UTF-8';
95 }
96
97 $xp = xml_parser_create($this->encoding);
98 xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, 0);
99 xml_set_object($xp, $this);
100 xml_set_element_handler($xp, 'startHandler', 'endHandler');
101 xml_set_character_data_handler($xp, 'cdataHandler');
102 if (!xml_parse($xp, $data)) {
103 $msg = xml_error_string(xml_get_error_code($xp));
104 $line = xml_get_current_line_number($xp);
105 xml_parser_free($xp);
106 include_once 'PEAR.php';
107 return PEAR::raiseError("XML Error: '$msg' on line '$line'", 2);
108 }
109 xml_parser_free($xp);
110 return true;
111 }

Referenced by PEAR_REST\retrieveData().

Here is the caller graph for this function:

◆ postProcess()

postProcess ( $data,
$element )

post-process data

Parameters
string$data
string$elementelement name

Reimplemented in PEAR_PackageFile_Parser_v2.

Definition at line 150 of file XMLParser.php.

151 {
152 return trim($data);
153 }

Referenced by endHandler().

Here is the caller graph for this function:

◆ startHandler()

startHandler ( $parser,
$element,
$attribs )

Start element handler for XML parser

@access private

Parameters
object$parserXML parser object
string$elementXML element
array$attribsattributes of XML tag
Returns
void

Definition at line 122 of file XMLParser.php.

123 {
124 $this->_depth++;
125 $this->_dataStack[$this->_depth] = null;
126
127 $val = array(
128 'name' => $element,
129 'value' => null,
130 'type' => 'string',
131 'childrenKeys' => array(),
132 'aggregKeys' => array()
133 );
134
135 if (count($attribs) > 0) {
136 $val['children'] = array();
137 $val['type'] = 'array';
138 $val['children']['attribs'] = $attribs;
139 }
140
141 array_push($this->_valStack, $val);
142 }

References $_depth.

Field Documentation

◆ $_dataStack

$_dataStack = array()

stack for all data that is found

Definition at line 47 of file XMLParser.php.

◆ $_depth

$_depth = 0

current tag depth

Definition at line 59 of file XMLParser.php.

Referenced by cdataHandler(), and startHandler().

◆ $_root

$_root = null

name of the root tag

Definition at line 41 of file XMLParser.php.

◆ $_unserializedData

$_unserializedData = null

Definition at line 35 of file XMLParser.php.

Referenced by getData().

◆ $_valStack

$_valStack = array()

stack for all values that are generated

Definition at line 53 of file XMLParser.php.

◆ $encoding

$encoding = 'ISO-8859-1'

The XML encoding to use

Definition at line 65 of file XMLParser.php.

Referenced by PEAR_PackageFile_Parser_v2\parse().


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/PEAR/XMLParser.php