You are here:  » Parsing Feed!


Parsing Feed!

Submitted by crounauer on Tue, 2007-03-27 15:54 in

Hi David,

I am trying to parse this feed, but am having difficulty getting all the different rates. Could you please shed some light?

[link saved]

I can't seem to get hold of the rates for the 28th onwards.

Thanks, Simon

Submitted by support on Tue, 2007-03-27 16:06

Hi Simon,

Accessing the additional dates involves using the @n postfix that Magic Parser adds to each additional date record to resolve sub-records of the same name within the record. The technique is to create a loop that keeps adding @1, @2 etc. to the date field until it is no longer set, and then use that postfix to access the date within each iteration.

Example Link

Here's the source code to the above file to demonstrate what I mean...

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    print 
"<h2>".$record["HOTEL_NAME"]."</h2>";
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      
$exists = isset($record["LR_RATES/HOTEL_ROOMS/ROOM/RATE".$postfix]);
      if (!
$exists) break;
      print 
"<li>";
      print 
$record["LR_RATES/HOTEL_ROOMS/ROOM/RATE/FORMATTED_DATE".$postfix];
      print 
" - ";
      print 
$record["LR_RATES/HOTEL_ROOMS/ROOM/RATE/PRICE".$postfix];
      print 
"</li>";
      
$i++;
    }
  }
  
MagicParser_parse("hotel.xml","myRecordHandler","xml|HOTEL_SEARCH/HOTEL/");
?>

Hope this helps!

Cheers,
David.