Hi
I'm trying to parse the structure of a xml data file with a php script but the result of it is just a blank page. When I running the same script, which has no class (not using the OO principe), i works well and i get the output.
Does anyone know what mistake I did?
<?
class UserHandler
{
var $file = "data.xml";
var $depth = array();
function startElement($parser, $name, $attrs) {
global $depth;
for ($i = 0; $i < $this->depth[$parser]; $i++) {
print " ";
}
print "$name\n";
$this->depth[$parser]++;
}
function endElement($parser, $name) {
global $depth;
$this->depth[$parser]--;
}
function read() {
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
//Permissioncheck of the xmlfile
if (!($fp = fopen($this->file, "r"))) {
die("could not open XML input"); }
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
xml_parser_free($xml_parser);
}
}
$obj = new UserHandler();
$obj->read();
?>
Thanks a lot!!
Cyrill