XML data not reading fully

Discussion in 'PHP' started by afridy, Nov 22, 2010.

  1. #1
    Hai folks,

    i am using below code to parse a large xml file.
    problem is, it's not reading the entire xml data,rather a small portion is only read.
    what could be the problem?

    $file  = "$url"; 
    function contents($parser, $data){
        echo $data;
    }
    function startTag($parser, $data){
        echo "<b>";
    }
    function endTag($parser, $data){
        echo "</b><br />";
    }
    
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startTag", "endTag");
    xml_set_character_data_handler($xml_parser, "contents");
    $fp = fopen($file, "r");
    $data = fread($fp, 80000); // Note i increased the size of this up to 2mb and result is same.
    if(!(xml_parse($xml_parser, $data, feof($fp)))){
        die("Error on line " . xml_get_current_line_number($xml_parser));
    }
    xml_parser_free($xml_parser);
    fclose($fp);
    
    PHP:
     
    afridy, Nov 22, 2010 IP