Greetings.
I have done a test class to wrap a xml parser. But im getting the following error: "xml_parse(): Unable to call handler startTag()", on this line "if(!(xml_parse($this->xml_parser, $this->data, feof($this->fp)))){ "
the code:
Greetings.
I have done a test class to wrap a xml parser. But im getting the following error: "xml_parse(): Unable to call handler startTag()", on this line "if(!(xml_parse($this->xml_parser, $this->data, feof($this->fp)))){ "
the code:
these are the final solutions:
<?php
class MyParser extends CApplicationComponent{
private $file = "/home/echo66/exemplo.xml";
private $xml_parser;
private $fp;
private $data;
protected function contents($parser, $data){
echo $data;
}
protected function startTag($parser, $data){
echo "<b>";
}
protected function endTag($parser, $data){
echo "</b><br />";
}
function init(){
$this->xml_parser = xml_parser_create();
//xml_set_object( $this->xml_parser, $this );
xml_set_element_handler( $this->xml_parser, array ( $this, 'startTag' ), array ( $this, 'endTag' ) );
xml_set_character_data_handler($this->xml_parser, array($this, 'contents') );
$this->fp = fopen($this->file, "r");
$this->data = fread($this->fp, 80000);
if(!(xml_parse($this->xml_parser, $this->data, feof($this->fp)))){
die("Error on line " . xml_get_current_line_number($this->xml_parser));
}
xml_parser_free($this->xml_parser);
fclose($this->fp);
}
function run(){
}
}
?>
<?php
class MyParser extends CApplicationComponent{
private $file = "/home/echo66/exemplo.xml";
private $xml_parser;
private $fp;
private $data;
protected function contents($parser, $data){
echo $data;
}
protected function startTag($parser, $data){
echo "<b>";
}
protected function endTag($parser, $data){
echo "</b><br />";
}
function init(){
$this->xml_parser = xml_parser_create();
xml_set_object( $this->xml_parser, $this );
xml_set_element_handler( $this->xml_parser, 'startTag', 'endTag' );
xml_set_character_data_handler($this->xml_parser, array($this, 'contents') );
$this->fp = fopen($this->file, "r");
$this->data = fread($this->fp, 80000);
if(!(xml_parse($this->xml_parser, $this->data, feof($this->fp)))){
die("Error on line " . xml_get_current_line_number($this->xml_parser));
}
xml_parser_free($this->xml_parser);
fclose($this->fp);
}
function run(){
}
}
?>
Thank for sharing