tags:

views:

52

answers:

2

Possible Duplicate:
Parsing Huge XML Files in PHP

I am trying to parse a 70Mb XML file under PHP. After a while the resources are not enough and the script crashes. If there is a larger XML file it ends sooner. I can't change the memory limit of the server and of PHP.

What can I do to parse large files? The file size can vary, and it's not always 70Mb, it could easily be 200Mb.

+4  A: 

You can use the XMLReader class.
It doesn't read the entire document as an object model into the memory but is a pull parser.

VolkerK
+1  A: 

In general, when you want to parse large XML documents in a constrained environment, you should use a SAX parser, that does not store the entire document in any form. SAX parsers make calls to user defined functions when they encounter an opening or closing tag for example.

netom
SAX is painful and too low-level for most parsing needs. I'd go with a pull parser.
Mark Thomas