You are here:  » One time parsing instead of a loop


One time parsing instead of a loop

Submitted by derek on Tue, 2005-12-06 00:09 in

thanks for your help,

I have another question.

right now, it is doing it like a loop,
is there anyway, I can just get all the array
to $record, and finally, I will just have $record[0]..$record[1]...
which holds all the record ?

thanks,

Derek

Submitted by support on Tue, 2005-12-06 07:27

Hi Derek,

You could simply add each record to a global array within your record handler function - code below, however if you are working with the 150MB file you mentioned in another post then I would not recommend this aproach. The best strategy would be to do whatever processing you need to do with each record within the record handler.

However, for completeness, here is the code you could use:

<?php
  
// setup a global variable to hold all records
  
$xml = array();
  
myRecordHandler($record)
  {
    global 
$xml;
    
// append this record to the end of the $xml array
    
$xml[] = $record;
  }
  
MagicParser_parse("/path/to/file.xml","myRecordHandler");
  
// you now how have every record in the $xml array...
?>

Submitted by derek on Tue, 2005-12-06 18:47

first of all, thanks for all your time and professional reply.
It is really userful.

I am going to try to see if I can parse 150 MB XML record.
I will try to parse it one by one and insert it to the database.
I will let you know if it works.

thanks

Submitted by medicalendar on Wed, 2007-07-18 17:30

Thanks for posting this - it helped me solve a similar issue with my record handler.