You are here:  » What is wrong with this XML Feed


What is wrong with this XML Feed

Submitted by globologic on Mon, 2010-03-22 03:31 in

Hi,

When I try the example on your home page, it doesn't seem to work.

Can you please advise how and what needs to be done to read this XML file?

{link saved}

Submitted by support on Mon, 2010-03-22 08:02

Hi,

That style of XML is not ideally suited to Magic Parser as it contains multiple repeating elements; however; if you are primarily interested in the event data, it will work fine using the Format String:

xml|EVENTDATA/MASTEREVENTS/EVENT/

I've uploaded the source to the demo tool with this Format String here.

Having said that, there is a straight forward way to extract each competitor value (per event) when parsing at the above level using the loop method; for example:

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    print 
$record["EVENT-EVENTNAME"];
    
$i 0;
    
$p "";
    do {
      if (
$i$p "@".$i;
      if (!
$record["COMPETITOR".$p."-COMPETITORNAME"]) break;
      
// this section repeats for every competitor
      
$competitorname $record["COMPETITOR".$p."-COMPETITORNAME"];
      
$betid $record["COMPETITOR".$p."-BETD"];
      
$bettypename $record["COMPETITOR/BETTYPE".$p."-BETTYPENAME"];
      
$price $record["COMPETITOR/BETTYPE".$p."-PRICE"];
      
$points $record["COMPETITOR/BETTYPE".$p."-POINTS"];
      
// end repeat
      
$i++;
    } while(
1);
  }
  
MagicParser_parse("{link saved}","myRecordHandler","xml|EVENTDATA/MASTEREVENTS/EVENT/");
?>

Hope this helps!
Cheers,
David.

Submitted by globologic on Tue, 2010-04-13 04:11

Hi David,

Thanks for that.

What is the best way to get that data in a mysql database?

Submitted by support on Tue, 2010-04-13 06:06

Hi,

Please see the following thread for an overview and example of inserting records into a database...

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

If you're not sure what field types etc. to use, in general, use VARCHAR(255) for general data types (i.e. titles, names etc.) and TEXT for longer fields such as description...

I would also recommend developing and testing your MySQL code in isolation from your parser code at first - especially if you have not written MySQL code before. Create your table, and then write a simple script that empties the table (TRUNCATE tablename) - which is normally the first step of a script to parse data into a database - and then inserts one record with dummy data. When you have that working, then it's just case of porting the code into your parsing script, constructing the INSERT SQL within your myRecordHandler function - remembering to use mysql_escape_string to make sure the data is safe and won't break your SQL!

Hope this helps!
Cheers,
David.