You are here:  » nested / sub nodes

nested / sub nodes

Submitted by Zeppen on Sat, 2010-05-01 18:34 in

Hi there!

im tryin to play around with magic parser but im not sure how to deal with child nodes.
what im tryin to do is to send selected info from the xml-file into the database.
later on I might be able to compare different bookies and so on..

the problem is child nodes, i dunno how to get thru all the games in the xml, it seems to stop after the first game so to speak..

xml-file looks like this:

{code saved}

and the php to save to mysql looks like this right now..

  mysql_connect("localhost", "*********", "***********") or die(mysql_error());
  mysql_select_db("*********") or die(mysql_error());
  $sql = "DELETE FROM myxml";
  $sql = "";
  $counter = 0;
  function myRecordHandler($product)
     global $counter;
     global $sql;
     $sql =
       "INSERT INTO myxml SET
              event = '".mysql_real_escape_string($product["EVENT"])."',
       event_name = '".mysql_real_escape_string($product["EVENT-NAME"])."',
       event_date = '".mysql_real_escape_string($product["EVENT-DATE"])."',
       event_time = '".mysql_real_escape_string($product["EVENT-TIME"])."',
       event_sport = '".mysql_real_escape_string($product["EVENT-SPORT"])."',
       event_sporttype = '".mysql_real_escape_string($product["EVENT-SPORTTYPE"])."',
       event_sb_url = '".mysql_real_escape_string($product["BETTYPE-SB-URL"])."',
       bettype_bet_start_date = '".mysql_real_escape_string($product["BETTYPE-BET-START-DATE"])."',
       bettype_bet_start_time = '".mysql_real_escape_string($product["BETTYPE-BET-START-TIME"])."',
       bettype_suspended = '".mysql_real_escape_string($product["BETTYPE-SUSPENDED"])."',
          bethadvalue_home = '".mysql_real_escape_string($product["BETTYPE/BET-HAD-VALUE"])."',
          bethadvalue_away = '".mysql_real_escape_string($product["BETTYPE/BET@1-HAD-VALUE"])."',
          betname_home = '".mysql_real_escape_string($product["BETTYPE/BET-NAME"])."',
          betname_away = '".mysql_real_escape_string($product["BETTYPE/BET@1-NAME"])."',
          betid_home = '".mysql_real_escape_string($product["BETTYPE/BET-ID"])."',
          betid_away = '".mysql_real_escape_string($product["BETTYPE/BET@1-ID"])."',
          betpricedecimal_home = '".mysql_real_escape_string($product["BETTYPE/BET-PRICEDECIMAL"])."',
          betpricedecimal_away = '".mysql_real_escape_string($product["BETTYPE/BET@1-PRICEDECIMAL"])."',
          betactivepricetypes_home = '".mysql_real_escape_string($product["BETTYPE/BET@1-ACTIVE-PRICE-TYPES"])."',
          betactivepricetypes_away = '".mysql_real_escape_string($product["BETTYPE/BET@1-ACTIVE-PRICE-TYPES"])."'
     if (!mysql_query($sql))
       // SQL failed, print error message and abort
       print mysql_error();exit();
  $url = "";
  print "<p>Processed ".$counter." records.</p>";
  print "<p>Last SQL statement was: ".$sql."</p>";

gives this message

Processed 1 records.
Last SQL statement was: INSERT INTO sjnba2 SET event = '\n-\n', event_name = 'Arizona Diamondbacks (Haren) @ Chicago Cubs (Silva)', event_date = '20100501', event_time = '1805', event_sport = 'Baseball-US', event_sporttype = 'Baseball', event_sb_url = '', bettype_bet_start_date = '20100501', bettype_bet_start_time = '1805', bettype_suspended = 'false', bethadvalue_home = 'HOME', bethadvalue_away = 'AWAY', betname_home = 'Arizona Diamondbacks (Haren)', betname_away = 'Chicago Cubs (Silva)', betid_home = '47796850.20', betid_away = '47796851.20', betpricedecimal_home = '1.83', betpricedecimal_away = '1.83', betactivepricetypes_home = 'CP', betactivepricetypes_away = 'CP'



Submitted by support on Sun, 2010-05-02 08:38

Hello Rick,

Would it be possible for you to email me a link to (or zipped / attached) the full XML file?

Normally Magic Parser would be used against a lower level repeating record, such as each BETTYPE. Using a Format String of xml|EVENT/ will return the entire document as a flat structure, with the child nodes represented, as you have discovered, along the lines of BETTYPE/BET etc., but using xml|EVENT/BETTYPE/ would return each BETTYPE individually which should be much easier to handle...

If you're not sure I'll check your XML and source and work out the best approach for you...


Submitted by Zeppen on Sun, 2010-05-02 20:38

wow - your support is one of a kind!

You sent me quick and quality answer by email with a good solution within an hour - on a sunday!!
Your support is something Ive never experienced before :)

Magic Parser is definitely worth the money :)