You are here:  » Only seeing xml code


Only seeing xml code

Submitted by asplash on Fri, 2009-06-12 13:33 in

Hi,

I have copied the code below which was generated using the demo which worked fine. I have uploaded all the files onto my server, but I am only seeing the xml content as one long page of code. I can see the BBC feed when I copy your code onto the server, and I can see the results of MagicParserTest.php as:
Array ( [DEMO] => [MESSAGE] => If you can read this message your Magic Parser installation is working! )

Should I be saving the file as name.php or name.xml ? Or am I barking up the wrong tree?

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    
// This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    
print_r($record);
    
// The following code will print out each field in your sample data:
    
print $record["PRODUCT"];
    print 
$record["PROGRAM_ID"];
    print 
$record["PROGRAM_NAME"];
    print 
$record["PRODUCT_ID"];
    print 
$record["PRODUCT_NAME"];
    print 
$record["DESCRIPTION"];
    print 
$record["DEEPLINK"];
    print 
$record["PRICE"];
    print 
$record["IMAGE_URL"];
    print 
$record["CATEGORIES"];
    print 
$record["CATEGORIES/CATEGORY"];
    print 
$record["CATEGORIES/CATEGORY-ID"];
    print 
$record["CATEGORIES/CATEGORY-PATH"];
    print 
$record["MERCHANT_CATEGORY"];
    print 
$record["LAST_UPDATED"];
  }
  
MagicParser_parse("webgainsproducts.xml","myRecordHandler","xml|PRODUCTS/PRODUCT/");
?>

Submitted by support on Fri, 2009-06-12 13:51

Hi,

The code above will just "dump" all the data - so it sounds like everything's working. It's intended just to show you how to access each of the fields in each record within your myRecordHandler() function.

The next step is now to remove the demo code from myRecordHandler, and process each of the records as required by your application, for example loading them into a database.

Hope this helps,
David.

Submitted by asplash on Fri, 2009-06-12 13:57

Sorry, I really dont know what you mean. Which part of the code is 'demo code from myRecordHandler' and what do I have to do to 'process each of the records as required by your application,'

Thanks for the speedy response!

Submitted by support on Fri, 2009-06-12 15:54

Hi There,

First - sorry for the delay in your messages appearing - I publish posts / comments manually so there may be a short delay sometimes, but they will appear!

By "your application", I mean what you ultimately want to do with the data you are parsing. Magic Parser is just a parser library; once it has extracted the data for you it is then up to whatever your application (i.e. your PHP script) wants to do with it.

I notice that you are working with an affiliate product feed - so your application might want to insert the products into a database for example - you'll find lots of MySQL examples in the forum (use the Google search box on that page).

By "demo code", I mean the code within the myRecordHandler() function (i.e. between the { } brackets). This is where you write your code to handle each record; using the elements of the $record array as you can see in the demo code (which is what caused it to just print out lots of data when you first ran the scritp!)

However, going back to affiliate product feeds; if you don't have much programming experience and would like to create a datafeed affiliate site, were you aware of my other product - Price Tapestry? Price Tapestry is an affiliate price comparison script that uses Magic Parser to import your products feeds into a database. Since you have already purchased Magic Parser, if you would like to go for Price Tapestry you only need to pay the difference - just email me if you would like to try it.

Hope this helps!
Cheers,
David.