Xml database Help!

Associate
Joined
25 Aug 2006
Posts
1,090
HI

After paying for a complete webstore once i have decided to create my own from scratch. I am currently running oscommerce but i have no problems with really any shop package. However my problem is that my supplier has a full stock
feed in xml which i can incoperate into my site to save me a lot of time.

Unfortunately this is where i become a NooB. I have searched through forums but i am finding it hard to find a novice friendly tutorial in how to implement it.
My supplier is reluctant to tell me as he sells a complete website with the database included.

Is there anything you guys can suggest or help me solve or plainly explain the steps i need to make to create this database and how to add it to my website.

Thanks in advance

Chris
 
Loop the XML data using PHP classes such as the DOM or SimpleXML, and upon each loop insert the item into the OSCommerce database. Depending on the database setup this might be problematic, how many items are in the XML file?
 
I think several hundred. Can you explain the loop process a little bit more for me.

I know its like spoon feeding a baby but im trying to fully understand all that is being suggested.

Thanks
 
Something like:

PHP:
<?php

/*

Just an example assuming you're inserting to an already-established MySQL database, with the XML's storage format something like:

<?xml version="1.0" encoding="UTF-8"?>
<products>
 <item>
  <id>1</id>
  <name>Telephone</name>
 </item>
 <item>
  <id>2</id>
  <name>Radio</name>
 </item>
</products>

*/

$doc = simplexml_load_file('x.xml');
foreach($doc->item as $item)
	mysql_query('INSERT INTO `database` (`id`, `name`) VALUES (' . $item->id . ', \'' . $item->name . '\')');

?>

Can you see what's going on? Adapt it to your needs depending on the XML file and database structure, but for each item in the XML file, a database entry will be added.

If you want to paste a snippet of the XML file and the database structure it would be more helpful.
 
Back
Top Bottom