Skip to content
Advertisement

Convert large XML file to CSV in PHP

I have a 50MB XML file. I want to convert it to a CSV file, but most methods I have found exhaust the server memory. Is there a good way to do this using a stream method such as XMLreader.

Advertisement

Answer

You’d want to use XmlReader to parse the XML, as it works as an event based parser – Eg. it doesn’t load everything into memory, but rather reads as it advances through the input file.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement