I got a gigantic XML that I would like to insert to my database. I have searched a lot solutions, but cant make anything to work actually. This one seems great, if it worked. Can you help me please?
XML FILE:
<EXPORT>
<PRODUCT>
<ID>1070</ID>
<CATALOG_NUMBER>plwcx100</CATALOG_NUMBER>
<IMAGES>
<IMAGE_URL>http://ift.tt/1BpM7Lw;
</IMAGES>
<PARAMETERS>
<ITEMS>
<PARAMETER_NAME>Rozteč</PARAMETER_NAME>
<PARAMETER_VALUE>5x108</PARAMETER_VALUE>
</ITEMS>
<ITEMS>
<PARAMETER_NAME>Průměr kola</PARAMETER_NAME>
<PARAMETER_VALUE>16"</PARAMETER_VALUE>
</ITEMS>
</PARAMETERS>
</PRODUCT>
<PRODUCT>...</PRODUCT>
</EXPORT>
PHP CODE:
$xml = new XMLReader();
$xml->open('product_example.xml');
while ($xml->read()) {
if ($xml->nodeType == XMLReader::ELEMENT) {
switch ($xml->name) {
case 'PRODUCT':
$cat = new SimpleXMLElement($xml->readOuterXML());
echo '<pre>'; print_r($cat); echo '</pre>';unset($cat);
/* I would like to insert values into database here */
break;
}
}
}
But this code doesnt work at all :-( I dont know why. When I put "EXPORT" into case statement I get what I need, but it is just in one cycle and thats too much for memory for the big XML files. Can anyone see a bug , or what can I change? I am solving this for too long. Thank you so much!
No comments:
Post a Comment