Forum Moderators: coopster
quick overview - i need to grab an xml list from a remote website, then using the nodes i need to then insert them into a mysql db.
basically a computer company is producing this file and we can get this xml and then populate a website from this xml file.
PHP Version 5.0.4 on the server im using
here is a snippet from the remote address:
<?xml version="1.0" encoding="utf-8"?><?xml version='1.0'?>
<response>
<result>OK</result>
<responsedatetime>12/01/2007 13:36:55</responsedatetime>
<product>
<stockcode>0GRLIFTVLR306N</stockcode>
<description>FLY DVBT HYBRID DIGITAL TV PCI RETAIL</description>
<extendeddescription>All Graded and Refurbished products carry a 30-day Dead On Arrival Warranty (rest of existing warranty if an RMA replacement). All product is likely to be incomplete, missing packaging and drivers etc. The price of these items has been reduced to reflect</extendeddescription>
<imageurl>http://www.website.com/images/GRLIF-TVLR306N.JPG</imageurl>
<stock>3</stock>
<price>20.00</price>
<category>0101</category>
</product>
<product>
repeated ...
</product>
</response>
im getting the code from the website using this:
$url = [website.com...]
$content = file_get_contents($url);
firstly, is this a good way of doing this as the xml document is about 50,000 lines of code - im thinking of memory issues and limitations of what can actually go into a variable.
what do i need to do to seperate all of the products and to then insert each of the nodes into the relevant fields into the db.
once this is done i can then make this a cron job to run during the night as i will need to empty the db and insert with this new content.
any help will be great and if you have any more question please ask away.
confused? i am!
Since you have PHP5, you can use SimpleXML [us2.php.net]. This should make this task relatively easy, although your script may timeout if there is that much information; you may want to think about this. Maybe only get a certain amount at a time? I don't know, but this should get you started!
Good luck! :)
im using this code, which can pick up the xml when im pointing it to a local xml file, but it does not get it when im grabing it from the remote url.
foreach($content as $product){
if (!empty($product->stockcode)){
echo 'stockcode: ' . $product->stockcode . '<br />';
echo 'description: ' . $product->description . '<br /><hr />';
echo 'price: ' . $product->price . '<br /><hr />';
echo 'category: ' . $product->category . '<br /><hr />';
}
}
this follows on from the previous code i posted.