This is not a great solution, but just need to add another option:
You can break many large XML files into chunks, especially those that are actually lists of similar elements (since I suspect that the file you are working with will be).
for example, if your document looks like this:
<dmoz> <listing>....</listing> <listing>....</listing> <listing>....</listing> <listing>....</listing> <listing>....</listing> <listing>....</listing> ... </dmoz>
You can read it in mega or two at a time, artificially wrap several full <listing> tags loaded into the root level tag, and then load them through simplexml / domxml (I used domxml when using this approach).
Frankly, I prefer this approach if you use PHP <5.1.2. XMLReader is available with 5.1.2 and higher, which is probably the best option, but before that you were stuck with either the aforementioned chunking strategy or the old SAX / expat lib. And I donโt know about all of you, but I HATE writing / maintaining SAX / expat parsers.
Please note, however, that this approach is NOT really practical when your document does not consist of many identical lower-level elements (for example, it works great for any list of files or URLs, etc., but it wonโt make sense to parse a large HTML document)
Frank Farmer May 26 '09 at 17:45 2009-05-26 17:45
source share