...

View Full Version : Broken XML Reader Script



mattd8752
03-10-2007, 08:50 PM
For some reason, this script isn't fully running through.

It is outputting 1<main>
When it should also print_r an array.

Heres the code, if anyone could find my problem, it would be appreciated.


<?php
class xmlread
{
function input($cont){
$this->data = $cont;
}

function read($main){
$data = $this->data;
$line = 0;
$level = 0;
$tag = 0;
while($line < sizeof($data)){
$inxml = FALSE;
if($inxml == FALSE){
if(trim($data[$line]) == "<".trim($main).">"){
$inxml == TRUE;
$level = 1;
echo "1";
echo $data[$line];
}

}else{
if($level == 1){
echo "2";
if(ereg("^<", trim($data[$line])) && ereg(">$", trim($data[line])) && !ereg("^</", trim($data[$line]))){
$tag = explode("<", $data[$line]);
$tag = explode(">", $tag[1]);
$tag = $tag[0];
$level = 2;
}elseif("<".$main.">" == trim($data[$line])){
echo "3";
$inxml = FALSE;
}
}elseif($level == 2){
if(ereg("^</", trim($data[$line])) && ereg(">$", trim($data[$line]))){
$level = 1;
$tag = 0;
}else{
$tagb = explode("<", $data[$line], 1);
$tagb = explode(">", $tagb[1], 1);
$tagc = $tagb[0];
$tagb = explode("<", $tagb[1], 1);
$fill = $tagb[0];
$tagb = explode(">", $tagb[1], 1);
if($tagb[0] != $tagc){
die("Error: XML");
}else{
$return[$tag][$tagc] = $fill;
}
}
}
}
$line++;
}
return $return;
}
}

$test = new xmlread;
$page = file('test.xml');
$test->input($page);
print_r($test->read('main'));
?>

PremiumBlend
03-11-2007, 06:25 AM
I'm not sure what version of PHP you're using, but I use the SimpleXML functions on my website. Just by looking at your code, these seem a lot simpler. Here is a link that shows the functions and stuff.

http://us3.php.net/simplexml



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum