You are here:  » Can someone help?


Can someone help?

Submitted by dj_danh on Sat, 2006-11-04 18:40 in

Im basically confused on how it all works.

Can magic parser allow me to take a xml file and then with that automatically input all the information into a sql database table.

I am using phpmyadmin at the host.

I just want to make sure before i buy.
im new to xml feeds.

Currently im using cartweaver for my products but this is taking a long time to add each product and is hard to keep on top of new products coming out.

Hope you guys can help.

Submitted by support on Sat, 2006-11-04 19:30

Hi there,

Thank you for your interest in Magic Parser.

I'm afraid however that Magic Parser does not provide any code for loading information from an XML feed into a database. This is something that you would have to code up specifically for your application within the record handler function. The record handler function is a function that is called automatically by Magic Parser for every record in your feed.

Cheers,
David.

Submitted by dj_danh on Sun, 2006-11-05 10:38

Thankyou David for your help, I can see what they mean by fast support. Do you know any website which would give me guidence with what I need to do?

Regards
Dan

Submitted by support on Sun, 2006-11-05 11:15

Hello Dan,

There is a very comprehensive PHP tutorial on the MySQL website:
http://dev.mysql.com/tech-resources/articles/ddws/index.html

To give you some idea of what a script using Magic Parser to load items from a feed into a database might look like; here's some example source code that would load items from an RSS feed (link, title and description) into a table with columns of the same names:

<?php
  
require("MagicParser.php");
  
$link mysql_connect('localhost''mysql_user''mysql_password')
   or die(
'Could not connect: ' mysql_error());
  
mysql_select_db('my_database')
   or die(
'Could not select database');
  function 
myRecordHandler($item)
  {
    
$sql "INSERT INTO items SET
             link = '"
.mysql_escape_string($item["LINK"])."',
             title = '"
.mysql_escape_string($item["TITLE"])."',
             description = '"
.mysql_escape_string($item["DESCRIPTION"])."'";
    
mysql_query($sql);
  }
  
// first we empty the database ready to load the new items
  
$sql "DELETE FROM items";
  
mysql_query($sql);
  
$url "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
  
// now we call Magic Parser and let myRecordHandler load each item into the database
  
MagicParser_parse($url,"myRSSRecordHandler","xml|RSS/CHANNEL/ITEM/");
?>

It will also be worth studying the MySQL section of the PHP manual along with this code:
http://uk.php.net/manual/en/ref.mysql.php

Note also the use of the mysql_escape_string() function. This is to ensure that the contents of the data from the feed do not corrupt the format the SQL that you are generating from it!

Hope this helps,
Regards,
David.