You are here:  » How to read only the 20 first lines of my xml files


How to read only the 20 first lines of my xml files

Submitted by umbro909 on Thu, 2007-07-05 13:58 in

Hi David (and everybody ;-) )

I've a little problem:

Because I need to parse (and display) 30 items at the same time, my Parser has to read 30 files.xml at the same.
And my problem is.. this 30 files are larges (+-5mb with 8000 lines).

But the only fields I need to display are contained in the 20 first lines of my xml files (and this for all xml files)

So, is there a way to read only the 20 first lines and ask to the Parser to stop reading the rest of thes files??

Because, I've tried to write a set_time_limit(ie: 5), but the result is... nothing is displayed!

Thanks a lot

Umbro909.

Submitted by support on Thu, 2007-07-05 14:01

Hi,

Because XML is a structured format, it is not possible to just read the first "n" lines, because you have to read the file on a record-by-record basis. However, Magic Parser makes it easy to just process the first "n" records, as you can return TRUE from your record handler function to make Magic Parser stop reading any more records.

There's some example code for doing this in the following thread:

http://www.magicparser.com/node/202

Hope this helps,
Cheers,
David.