I have 2 large XML files which contains product details of a webshop. The first contains the product codes, names, and informations about the product avaibilities in stock, the second contains the product codes too, furthermore the names, the prices and other details of the products. I have to create a list of the products avaible in stock with all details, outputted to a (html) table.
My problem is the following: in the XML files are about 13000 products. With the first step (outputting the codes of the avaible products) i haven't problems, but when i try output the data from the second xml too, it doesn't works, the browser always shows "no data received". It's logical, there are about 2000-3000 products avaible in stock, what means, that the second XML file should be readed through 2000-3000 times.
How can i solve this problem? I can edit only the second XML file, the first is loaded from an external source, where i doesn't have access. Should I import the second XML file to an SQL table, or that isn't a good idea neither? Then what should i do?
Thanks (and sorry for the little bad english)!
My PHP code:
<?php
$zasoby_xml = file_get_contents('zasoby.xml');
$sxe0 = new SimpleXMLElement($zasoby_xml);
$sxe0->registerXPathNamespace('lStk', 'http://www.stormware.cz/schema/version_2/list_stock.xsd');
$lStkStock = $sxe0->xpath('//lStk:stock');
$cnt = count($lStkStock);
$sxe = new SimpleXMLElement($zasoby_xml);
$sxe->registerXPathNamespace('stk', 'http://www.stormware.cz/schema/version_2/stock.xsd');
$stkCode = $sxe->xpath('//stk:code'); //product code
$stkName = $sxe->xpath('//stk:name'); //product name
$stkCount = $sxe->xpath('//stk:count'); //count in the stock
$db_xml = simplexml_load_file('db.xml');
for ($i = 0;$i < $cnt;$i++) {
if ($stkCount[$i] > 0) {
echo $stkCode[$i]." ";
$j = 0;
while($stkCode[$i] != $db_xml->record[$j]->product_id) {
$j++;
}
echo $db_xml->record[$j]->category_path."<br>";
}
}
?>
First XML file example:
<?xml version="1.0" encoding="Windows-1250"?>
<rsp:responsePack version="2.0" id="Usr01" state="ok" note="46895680" programVersion="10608.3 E1 (13.3.2014)" xmlns:rsp="http://www.stormware.cz/schema/version_2/response.xsd" xmlns:lStk="http://www.stormware.cz/schema/version_2/list_stock.xsd" xmlns:stk="http://www.stormware.cz/schema/version_2/stock.xsd">
<rsp:responsePackItem version="2.0" id="Usr01" state="ok">
<lStk:listStock version="2.0" dateTimeStamp="2014-04-08T14:18:14" dateValidFrom="2014-04-08" state="ok">
<lStk:stock version="2.0">
<stk:code>90000000</stk:code>
<stk:count>975.0</stk:count>
<stk:name>Product name</stk:name>
</lStk:stock>
</lStk:listStock></rsp:responsePackItem></rsp:responsePack>
Second XML file example:
<?xml version="1.0" encoding="utf-8" ?>
<data>
<record>
<product_id><![CDATA[77778888]]></product_id>
<name><![CDATA[productname]]></name>
<Deeplink><![CDATA[product url]]></Deeplink>
<Img_url><![CDATA[product img_url]]></Img_url>
<category_path><![CDATA[product category]]></category_path>
<Price><![CDATA[product price]]></Price>
</record>
</data>