You are here:  » Converting this XML feed into the format I have as an example


Converting this XML feed into the format I have as an example

Submitted by JohnnyBoy on Mon, 2007-03-19 16:45 in

Hello and thank you in advance to anyone who can help...

I have this XML feed as an example for this is just one sport

"http://www.pointspread.com/liveodds/xml/xml_general_nba.xml"

I would like the output to be in a table format just like this example below...

http://www.pointspread.com/liveodds/index.php?sport=nba&page=1&interval=60&ltype=1&type=&getmonth=03&getday=19&getyear=2007

of course instead of 11 different companies which the data represents I will only use like 6 of my chosing...

I am having issues formating it to this degree...

Thank you again for any help...

Submitted by JohnnyBoy on Mon, 2007-03-19 17:01

OH!!! and of course this data from this XML feed is always being updated and refreshed constantly... So it can have two rows to twenty any givin time... So I assume it would have to be looped till no more rows can be filled... Thanks

Submitted by support on Mon, 2007-03-19 17:19

Hi,

This sort of XML document is not well suited to Magic Parser because it contains repeating records within repeating records. However, it can be done. What I have done is create a quick Magic Parser example showing you how to extract each game and display the different odds in a table. Here's the example running on this server:

http://www.magicparser.com/examples/nba.php

Here's the source code:

<?php
  
require("MagicParser.php");
  print 
"<style type='text/css'>table {font-size: small; }</style>";
  function 
myRecordHandler($record)
  {
    print 
"<h2>".$record["GAME-HOMENAME"]." Vs ".$record["GAME-AWAYNAME"]."</h2>";
    print 
"<table border='1'>";
    print 
"<tr>";
    print 
"<th>Book</th>";
    print 
"<th>AwayML</th>";
    print 
"<th>HomeML</th>";
    print 
"<th>AwaySpread</th>";
    print 
"<th>AwayLine</th>";
    print 
"<th>HomeSpread</th>";
    print 
"<th>HomeLine</th>";
    print 
"<th>Total</th>";
    print 
"<th>OverLine</th>";
    print 
"<th>UnderLine</th>";
    print 
"</tr>";
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      if (!
$record["BOOK".$postfix."-NAME"]) break;
      print 
"<tr>";
      print 
"<th>".$record["BOOK".$postfix."-NAME"]."&nbsp;</td>";
      print 
"<td>".$record["BOOK".$postfix."-AWAYML"]."&nbsp;</td>";
      print 
"<td>".$record["BOOK".$postfix."-HOMEML"]."&nbsp;</td>";
      print 
"<td>".$record["BOOK".$postfix."-AWAYSPREAD"]."&nbsp;</td>";
      print 
"<td>".$record["BOOK".$postfix."-AWAYLINE"]."&nbsp;</td>";
      print 
"<td>".$record["BOOK".$postfix."-HOMESPREAD"]."&nbsp;</td>";
      print 
"<td>".$record["BOOK".$postfix."-HOMELINE"]."&nbsp;</td>";
      print 
"<td>".$record["BOOK".$postfix."-TOTAL"]."&nbsp;</td>";
      print 
"<td>".$record["BOOK".$postfix."-OVERLINE"]."&nbsp;</td>";
      print 
"<td>".$record["BOOK".$postfix."-UNDERLINE"]."&nbsp;</td>";
      print 
"</tr>";
      
$i++;
    }
    print 
"</table>";
  }
  
MagicParser_parse("nba.xml","myRecordHandler","xml|ODDS/GAME/");
?>

Hope this helps!
Cheers,
David.

Submitted by JohnnyBoy on Mon, 2007-03-19 17:39

You guys rock... Looks like it works great to me... My only question is that if I want to specifiy certain books instead of listing all of them then how can I query only the ones I want to use... for example (bodog2, Beted2, sportinteraction2, vipsports2, betgameday2, sportsbook).. would that be an if / then statement?

Thank you so much...

Submitted by support on Mon, 2007-03-19 17:44

Hi,

To do that the easiest way is to create an array containing a list of the books you want, and then within the loop only display the book if the NAME is in the list. For example:

      $useBooks = array("bodog2"=>1,"Beted2"=>1);
      $i = 0;
      while(1) {
      if ($i) $postfix = "@".$i;
      if (!$record["BOOK".$postfix."-NAME"]) break;
      if ($useBooks["BOOK".$postfix."-NAME"])
      {
        print "<tr>";
        print "<th>".$record["BOOK".$postfix."-NAME"]."&nbsp;</td>";
        print "<td>".$record["BOOK".$postfix."-AWAYML"]."&nbsp;</td>";
        print "<td>".$record["BOOK".$postfix."-HOMEML"]."&nbsp;</td>";
        print "<td>".$record["BOOK".$postfix."-AWAYSPREAD"]."&nbsp;</td>";
        print "<td>".$record["BOOK".$postfix."-AWAYLINE"]."&nbsp;</td>";
        print "<td>".$record["BOOK".$postfix."-HOMESPREAD"]."&nbsp;</td>";
        print "<td>".$record["BOOK".$postfix."-HOMELINE"]."&nbsp;</td>";
        print "<td>".$record["BOOK".$postfix."-TOTAL"]."&nbsp;</td>";
        print "<td>".$record["BOOK".$postfix."-OVERLINE"]."&nbsp;</td>";
        print "<td>".$record["BOOK".$postfix."-UNDERLINE"]."&nbsp;</td>";
        print "</tr>";
      }
      $i++;
      }

Hope this helps,
Cheers,
David.

Submitted by JohnnyBoy on Mon, 2007-03-19 18:22

I tried putting in the array as you suggested and what resulted is no data being shown for any books... I might have my syntax wrong or something to that affect. Below is a link to the code that I used for some reason it will not allow me to post the code on here because of suspicous content is what it says...

Also I just realized that this is just NBA... So, it only has two games this night, but if it was baseball there could be 40 games going on at one time, and that would kill the page in lenght. So, I would need the first column to be the list of games by teams playing each other, and then the books being each column with its data for each game. which I am sure I can play with it and make it work but if you have any suggestions then I would take them with open arms.. This is a complicated feed to me and you guys here have been really great... The only thing I am really jealous of is that you guys have beckham... :) Thanks Again!!!

http://www.sportsrumble.com/xml/index2.php

Submitted by support on Mon, 2007-03-19 18:29

Hi,

Sorry - my mistake the test into the array was incorrect. Here's the corrected version:

<?php
  
require("MagicParser.php");
  print 
"<style type='text/css'>table {font-size: small; }</style>";
  function 
myRecordHandler($record)
  {
    print 
"<h2>".$record["GAME-HOMENAME"]." Vs ".$record["GAME-AWAYNAME"]."</h2>";
    print 
"<table border='1'>";
    print 
"<tr>";
    print 
"<th>Book</th>";
    print 
"<th>AwayML</th>";
    print 
"<th>HomeML</th>";
    print 
"<th>AwaySpread</th>";
    print 
"<th>AwayLine</th>";
    print 
"<th>HomeSpread</th>";
    print 
"<th>HomeLine</th>";
    print 
"<th>Total</th>";
    print 
"<th>OverLine</th>";
    print 
"<th>UnderLine</th>";
    print 
"</tr>";
    
$showBooks = array("beted2"=>1,"betjamaica2"=>1);
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      if (!
$record["BOOK".$postfix."-NAME"]) break;
      if (
$showBooks[$record["BOOK".$postfix."-NAME"]])
      {
        print 
"<tr>";
        print 
"<th>".$record["BOOK".$postfix."-NAME"]."&nbsp;</td>";
        print 
"<td>".$record["BOOK".$postfix."-AWAYML"]."&nbsp;</td>";
        print 
"<td>".$record["BOOK".$postfix."-HOMEML"]."&nbsp;</td>";
        print 
"<td>".$record["BOOK".$postfix."-AWAYSPREAD"]."&nbsp;</td>";
        print 
"<td>".$record["BOOK".$postfix."-AWAYLINE"]."&nbsp;</td>";
        print 
"<td>".$record["BOOK".$postfix."-HOMESPREAD"]."&nbsp;</td>";
        print 
"<td>".$record["BOOK".$postfix."-HOMELINE"]."&nbsp;</td>";
        print 
"<td>".$record["BOOK".$postfix."-TOTAL"]."&nbsp;</td>";
        print 
"<td>".$record["BOOK".$postfix."-OVERLINE"]."&nbsp;</td>";
        print 
"<td>".$record["BOOK".$postfix."-UNDERLINE"]."&nbsp;</td>";
        print 
"</tr>";
      }
      
$i++;
    }
    print 
"</table>";
  }
  
MagicParser_parse("nba.xml","myRecordHandler","xml|ODDS/GAME/");
?>

You right - there are plenty of ways you can work around this to adjust the formatting; but in order to display a column of games you would need to start the table outside of the record handler function, and then have the record handler create each table row. The outline would be something like this:

<?php
  
print "<table>";
  function 
myRecordHandler($record)
  {
    print 
"<tr>";
    
// create the game / books entry in this row
    
print "</tr>";
  }
  
// parse the file to populate the rows
  
MagicParser_parse(...);
  
// finally close the table
  
print "</table>";
?>

Cheers...
David.

Submitted by JohnnyBoy on Mon, 2007-03-19 18:43

Yeahhhhhhhhh Boooy... Gotch ya... all working fine!!! Well so far. Just give me a little bit and I can change that.. :) .. The format explanation above actually makes complete sense... So far you guys have been the most helpful and insightful bunch regarding this topic... Defintely would recommend you guys to anyone and everyone... Ciao for now!!!

Submitted by JohnnyBoy on Tue, 2007-03-20 18:18

Question... When the array was created for the books you use the values for each book chosen as ("beted2"=>1). So in other words the value of beted2 is equal or greater then 1.. I think I understand that if its equal to one then it displays the data criteria once but then the greater than one is where I am confused... maybe I am just barking up the wrong tree all together.. I am just trying to understand the syntax.. Thanks for your help...

Submitted by support on Wed, 2007-03-21 10:30

Hi,

The actual value is irrelevant as long as it evaluates to TRUE. Infact, we could have used ("beted2"=>TRUE) which would work just as well. The value is then tested within the loop to see if the $useBooks array has an entry for that book name, and then displays the book if so...

Hope this helps,
Cheers,
David.