Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Broken XML Reader Script

    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 Code:
    <?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'));
    ?>

  • #2
    Regular Coder PremiumBlend's Avatar
    Join Date
    Apr 2006
    Location
    Marion, Iowa
    Posts
    201
    Thanks
    0
    Thanked 13 Times in 13 Posts
    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
    My Website: DumpsterDoggy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •