You are here:  » Complex XML Feed


Complex XML Feed

Submitted by shawnwalters on Tue, 2007-04-10 18:21 in

I have a very complex feed, which I've file imploded here: {link saved}

But it separates different content by "engine name". So how do I do something like "if engine name=sponsored" then show results? Is this possible?

Thanks,
Shawn

Submitted by support on Mon, 2007-04-16 08:28

Hi Shawn,

I've saved the URL you provided, however there is no data being displayed on that page at the moment. If you are still looking for help with this feed let me know when the same is back up and i'll take a look for you!

Cheers,
David.

Submitted by shawnwalters on Fri, 2007-04-20 22:35

Sorry David,

Here is the url: {snipped}

I had to use fopen because only the server's IP is allowed to access the feed. So just select view source to see what the feed is.

Currently, my magicparser php code is super long because I have to check for each individual record to see if it exists first. For example:

if (($record["RESULTSET-ENGINECODE"] == "pl")){
if (($record['RESULTSET/RESULT/TITLE'])){
//then display that record
}
if (($record['RESULTSET/RESULT/TITLE@1'])){
//then display that record using @1 with everything
}
}
etc, etc.

( if this is a paid support issue, please let me know how to proceed.)

Thanks again,
Shawn

Submitted by support on Sat, 2007-04-21 17:09

Hi Shawn,

This is the sort of situation where you need to parse your feed at a higher level (shorter format string); and then use a loop to resolve the multiple results that will then be within a single record.

I saved the XML from your link as "ask.xml", and used the example code below to display sponsored results. I've not put the example online for the same reason that you did not want the source XML URL displayed; but you can easily modify this example to parse the URL directly of course.

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($record)
  {
    
// only continue if engine name is sponsored
    
if ($record["ENGINE-NAME"] != "sponsored") return;
    
// now process the resolved duplicated records RESULTSET/RESULT for display
    
$i 0;
    while(
1) {
      if (
$i$postfix "@".$i;
      if (!isset(
$record["RESULTSET/RESULT".$postfix])) break;
      
$title $record["RESULTSET/RESULT/TITLE".$postfix];
      
$baseuri $record["RESULTSET/RESULT/BASEURI".$postfix];
      
$rediruri $record["RESULTSET/RESULT/REDIRURI".$postfix];
      
$abstract $record["RESULTSET/RESULT/ABSTRACT".$postfix];
      print 
"<h4><a href='".$rediruri."'>".$title."</a></h4>";
      print 
"<p>".$abstract."</p>";
      print 
"<p>".$baseuri."</p>";
      
$i++;
    }
  }
  print 
"<h3>Sponsored Results</h3>";
  
MagicParser_parse("ask.xml","myRecordHandler","xml|AJRESULTS/ENGINE/");
?>

Hope this points you in the right direction!
Cheers,
David.