I have written the following code - and there is a problem. When I refer to $this->html within the function parse_xml($xml) after the xml parsing function has been called, it appears to be empty. But if I refer to it as the HTML sections are added by the xml event handlers then the content appears to be there - could you please refer me to the relevant documentation or tell me what is wrong?
<?
$me = new page_boy;
$me->parse_xml("<?xml version='1.0' ?><red>This is red</red>");
 
class page_boy
{
var $db_connection;
var $html;
var $interface;
var $parser;

 function page_boy()
 {
  $this->db_connection = @mysql_connect("%%%%", "%%%%", "%%%%");
  @mysql_select_db("xgoat", $this->db_connection);
  $this->interface = 1;
  $this->html = "";
 
  $this->parser = xml_parser_create();
  xml_set_object($this->parser, &$this);
  xml_set_element_handler($this->parser, "start_tag", "end_tag");
  xml_set_character_data_handler($this->parser, "cdata");
 }
 
 function parse_xml($xml)
 {
  xml_parse($this->parser, $xml);
  echo $this->html;
 }
 
 function start_tag($r_parser, $tagname, $tag_att)
 {
  $qre = mysql_query("SELECT content FROM tags WHERE mode = $this->interface
       AND type = 'open'
       AND name = '$tagname'", $this->db_connection);
  $r_arr = mysql_fetch_array($qre);
  $this->add_content($r_arr["content"]);
 }
 
 function end_tag($r_parser, $tagname)
 {
  $qre = mysql_query("SELECT content FROM tags WHERE mode = $this->interface
        AND type = 'close'
        AND name = '$tagname'", $this->db_connection);
  $r_arr = mysql_fetch_array($qre);
  $this->add_content($r_arr["content"]);
 }
 
 function cdata($r_parser, $cdata)
 {
  $this->add_content($cdata);
 }
 
 function add_content($ncnt)
 {
  $this->html = $this->html . $ncnt;
  echo $ncnt;
 }
 
}
 
?>

Reply via email to