As part of my on going work of helping to migrate an e-commerce site to Magento, I’ve discovered that I need to parse a very large (>350MB) XML file. My first instinct was to use the SimpleXML parser. After a short test, where loading the file took 20 minutes and used up all of my computers memory, I looked for another solution. XMLReader (it comes with php 5.1) is the answer. It’s not as “pretty” as SimpleXML but its a stream processor so it does not have to load the entire file into memory to process it. This means you can more or less process record by record. Here are a few links that show how to use it:
http://www.ibm.com/developerworks/xml/library/x-xmlphp2.html
http://www.ibm.com/developerworks/library/x-pullparsingphp.html
http://blog.liip.ch/archive/2004/05/10/processing_large_xml_documents_with_php.html
Your article spurred me to look into this myself. We are using a script to update and create new products in magento and our current xml php parser http://keithdevens.com/software/phpxml is cringing at large files. I was able able to create parse, call, and print different fields from our xml file using a simple script, but am having some issues integrating into our file that creates products. I was wondering if you could post some examples. Thanks for the useful info.
Here’s a quick example:
Juice, thanks for the example, I just tried it and it’s working perfectly, but I’ve a little problem, even if I change the value for qty I allways get 0
, any clue?. thansk in advance.
I’m not using Magneto to manage stock, so I haven’t had any need to try to set the qty to anything other than 0. But if you have configured Magento to manage stock through its admin interface, you may be able to try:
$stockItem->setQty(100)