XML : codeigniter pass dynamic popluating array from model to view

Hi I need some help regarding passing an array which is being populated in model to view. Let me explain: Actually, i am using SAX XML parser to parse huge xml feeds from an external link. I am restricted to use only 32 MB memory and cant save the xml feeds as local file. So using SAX, in a while loop, i read 4mb of feed, then can echo or assign in an array, then free the SAX parser object to free memory, and so on. Now, XML in being parsed accurately, but this whole thing is being done in model. How can i pass the read feed to view while to loop is continuously reading feed. Code is

      $parser = xml_parser_create();      xml_set_element_handler($parser, Array(&$this, "startElements"), Array(&$this, "endElements"));        xml_set_character_data_handler($parser, Array(&$this, "characterData"));        // open xml file      if (!($handle = fopen($url, "r"))) {          die("could not open XML input");      }      while ($data = fread($handle, 4096)) { // read xml file          xml_parse($parser, $data);  // start parsing an xml document       }      xml_parser_free($parser); // free/delete the parser          public function characterData($parser, $data)       {      global $products, $elements;      if (!empty($data)) {          if ($elements == 'NAME' || $elements == 'PRICE' || $elements == 'PRODUCTURL' || $elements == 'PRODUCTID' || $elements == 'CATEGORY'|| $elements == 'IMAGEURL') {              $products[count($products) - 1][$elements] = trim($data);          }      }  }    

Please help how can i show the products array in view, as loop is continuously populating the products array, and i cant load the whole feed in memory buffer.

No comments:

Post a Comment