You are here:  » Hello, I have a question for users and Site Admins


Hello, I have a question for users and Site Admins

Submitted by coreyr on Mon, 2007-06-04 00:06 in

Hello first off, I have never used Magic Parser but I am very interested in using it. First, I have a few questions and the money is a lot for me right now but if it's worth it I will buy the program today.

1. Can I use this on multiple websites I have?
2. What are the draw backs if any?

Will it support my project?

I have four XML feeds I need to grab from URL's and save the files to my server. Open the files and then parse the XML. Once they are parsed, I need to create HTML from the dynamic XML data and store it to a HTML file on the server.

Is this supported?

Thank You,

Corey R.

Submitted by support on Mon, 2007-06-04 06:36

Hello Corey,

Thank you for your interest in Magic Parser.

You can use the script on as many of your own websites / domains etc. as you like - the license is for you - the only limitation is that you cannot redistribute the script in any way - that's all.

With regards to draw backs, remember that Magic Parser is designed for processing XML documents that contain many repeating records of the same time. It is not suitable for single, generic XML documents that contain lots of relatively unstructured information.

By repeating records, I mean things like affiliate product feeds, RSS and Atom feeds, results from search engine APIs - that sort of thing. It makes processing these sorts of files easy by calling your record handler function once for every record in the feed - so you don't have any of the complicated manipulation of multi-dimensional arrays that other parsing methods involve.

With regards to you project, you can use the demo tool on this website to see whether Magic Parser is going to be suitable:

http://www.magicparser.com/demo/

Simply input the URL of each of the feeds you need to grab into the second form, and see if you are able to navigate through the feeds using the table and navigation links that are displayed. If you can, then you can use the "Generate PHP Source" button to see how to use that URL in your own code.

If you're not sure about, post the URLs here if you're able to (if you don't want to post them in public feel free to drop me an email - reply to your forum registration email is the easiest way to get me) and i'll take a look for you.

Haveing verified that Magic Parser can handle the feeds, the rest of your requirement depends on the level of PHP knowledge that you have or have access to. Creating HTML is straight forward, you can just do this directly within the record handler function - see the following BBC News example to see how this is done:

http://www.magicparser.com/node/26

What you want to do is not that much more complicated. Instead of outputting the HTML directly to the browser, you would generate your HTML into a global variable ($html for example!) and then when the parser has finished, simply write $html out to a file. Here's what I mean, based on the BBC News example from above:

<?php
  
require("MagicParser.php");
  
// start your $html variable
  
$html "<html><body>";
  
$html .= "<h1>BBC News Headlines</h1>";
  function 
myRecordHandler($item)
  {
    global 
$html;
    
// add each record in the feed to $html
    
$html .= "<h2><a href='".$item["LINK"]."'>".$item["TITLE"]."</a></h2>";
    
$html .= "<p>".$item["DESCRIPTION"]."</p>";
  }
  
$url "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml";
  
MagicParser_parse($url,"myRecordHandler","xml|RSS/CHANNEL/ITEM/");
  
// finish the $html variable
  
$html "</body></html>";
  
// write $html to a file, news.html in this example
  
$file fopen("news.html","w");
  
fwrite($file,$html);
  
fclose($file);
?>

In the above code, the feed would be converted into HTML and then written to a file called "news.html" in the current directory. For this to work, remember that PHP must have WRITE access to the directory that you want to create the HTML file in.

Hope this helps!
Cheers,
David.