Y
Y
yurik_maz2017-02-08 17:43:25
PHP
yurik_maz, 2017-02-08 17:43:25

How to move to the desired element by index in a large xml file?

There are xml files larger than 2 gig, there is an example script for processing, like:

$reader = new XMLReader();
$reader->open($file);
while ($reader->read() && $reader->name !== 'item');
while ($reader->name === 'item') {
       /// обрабатываем данные и идем к следующему....

       $reader->next('item');
}
$reader->close();

Question: how to quickly drive the cursor, for example, to 125,000 item's and start processing from this position? The option of running in a loop with the reader method next('item') until there is 125,000 position is not suitable, since it can take extra time, from a minute or more ...
Are there any other implementation options?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WQP, 2017-02-08
@WQP

Initially split the file. Wait once, but work without delay
file.xml-> _file(0-10000).xml..._file(115000-125000).xml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question