This will depend on the layout of your XML file. But if this is something similar to RSS in that it is really just a long list of elements (all encapsulated in a tag), then what I did is to parse individual sections and parse them as separate domdocuments:
$buffer = ''; while ($line = getLineFromFtp()) { $buffer .= $line; if (strpos($line, '</item>') !== false) { parseBuffer($buffer); $buffer = ''; } }
This is pseudo code, but it is an easy way to process a specific type of XML file without creating your own XMLReader. Of course, you will also need to check the opening tags to ensure that the buffer is always a valid xml file.
Note that this will not work with all types of XML. But if it is suitable, this is a simple and understandable way to do this, while at the same time preserving the maximum possible amount of memory ...
source share