44 $this->parser = xml_parser_create(
'UTF-8');
45 xml_set_object($this->parser, $this);
46 $this->input =& $input;
49 xml_set_element_handler($this->parser,
'handleBeginElement',
'handleEndElement');
50 xml_set_character_data_handler($this->parser,
'handleCharacterData');
51 xml_set_processing_instruction_handler($this->parser,
'handleProcessingInstruction');
52 xml_set_default_handler($this->parser,
'handleDefault');
53 xml_set_unparsed_entity_decl_handler($this->parser,
'handleUnparsedEntityDecl');
54 xml_set_notation_decl_handler($this->parser,
'handleNotationDecl');
55 xml_set_external_entity_ref_handler($this->parser,
'handleExternalEntityRef');
76 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, $this->isCaseFolding);
84 $this->targetEncoding =
'ISO-8859-1';
85 xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->targetEncoding);
93 $this->targetEncoding =
'US-ASCII';
94 xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->targetEncoding);
102 $this->targetEncoding =
'UTF-8';
103 xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, $this->targetEncoding);
112 return $this->tags[count($this->tags) - 1];
117 if (isset($this->tags[count($this->tags) - 2])) {
118 return $this->tags[count($this->tags) - 2];
134 if (!is_resource($this->input)) {
135 if (!xml_parse($this->parser, $this->input)) {
144 while ($data = fread($this->input, 4096)) {
145 if (!xml_parse($this->parser, str_replace(
"'",
"'", $data), feof($this->input))) {
147 fclose($this->input);
151 fclose($this->input);
161 xml_parser_free($this->parser);
163 if (!method_exists($this,
'__destruct')) {
177 return sprintf(
"XmlParse error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser));
195 $name = $tagHandler->getName();
196 if (is_array($name)) {
197 foreach ($name as $n) {
198 $this->tagHandlers[$n] =& $tagHandler;
201 $this->tagHandlers[$name] =& $tagHandler;
222 array_push($this->tags, $tagName);
224 if (isset($this->tagHandlers[$tagName]) && is_subclass_of($this->tagHandlers[$tagName],
'xmltaghandler')) {
225 $this->tagHandlers[$tagName]->handleBeginElement($this, $attributesArray);
241 array_pop($this->tags);
242 if (isset($this->tagHandlers[$tagName]) && is_subclass_of($this->tagHandlers[$tagName],
'xmltaghandler')) {
243 $this->tagHandlers[$tagName]->handleEndElement($this);
260 if (isset($tagHandler) && is_subclass_of($tagHandler,
'xmltaghandler')) {
261 $tagHandler->handleCharacterData($this, $data);
348 $this->errors[] = trim(
$error);
363 if (count($this->errors) > 0) {
364 foreach ($this->errors as
$error) {
365 $ret .= $error.
'<br />';