PHPverse 2025

Voting

: nine plus zero?
(Example: nine)

The Note You're Voting On

zitan at mediasculpt dot net
21 years ago
Just a note about creating abstract "call back handlers" as mentioned in some of the other notes. In this case I recommend extending the base XML class and overwritting the handler methods. The reason I wanted to do this, is that if you have a separate callback method class it causes problems, for example if you want to collect information out of the XML file and store it in an array. You can get around it with global variables, but I prefer to use them only when required ;)

Example:

<?php
class xml_output extends xml{

var
$output = array();

function
xml_output(){
$this->xml();
}

//overwrite base methods
function tag_open($parser, $tag, $attributes)
{
array_push($this->output, "<$tag, attributes>");
}

function
cdata($parser, $cdata)
{
array_push($this->output, "$cdata");
}

function
tag_close($parser, $tag)
{
array_push($this->output, "</$tag>");
}

}

$xml_parser = & new xml_output();
$xml_parser->parse("<A ID='hallo'>PHP</A>");
echo(
"$xml_parser->output");
?>

<< Back to user notes page

To Top