I am trying to avoid XMLReader for an app I build that has a huge XML file.
SimpleXML is easy to write and I was wondering if there is any way to successfully handle it (memory and performance issues) in a quite busy server.
What I will do, is to echo some data from that XML mainly from a search form.
I am trying to avoid XMLReader for an app I build that has a
Share
Ok, if you really want to do this without XMLReader, here’s what you could do.
Use fopen to open and read N number of bytes of that file.
Fix the ending : (That’s the tough part but it’s perfectly doable)
You do it by closing anything left unclosed and also if needed backtracking if you happen to be in the middle of some text.
When that XML chunk is finally valid you can parse it with simplexmL.
Process that chunk or save it in its separate XML file
and create another chunk …until you have all of them.
Obviously if your XML is complex this might get a little painful.
Summary :
By creating your own custom/dirt-cheap xml parser/fixer you can split a huge XML file into multiple smaller files.