You are here:  » Recursive calls to MagicParser


Recursive calls to MagicParser

Submitted by apienczy on Tue, 2012-09-11 14:10 in

I have a situation where I need to get more information about every record from another xml file. So in more detail the steps will be as follows:

1. Parse master xml file calling it with record handler for this file
2. Witin the master xml record handler call MagicParser with another xml file specific for this record with its own record handler.

Will that work correctly?

Thanks in advance for your help.
-A

Submitted by support on Tue, 2012-09-11 14:57

Hi,

Rather than call Magic Parser recursively (as internally it relies on global variables) all you need to do is parse your first feed into a global $records array; and then process that array using foreach() just as if you were inside myRecordHandler; except that you can start a new parse - and access the parent $record via a global declaration...Consider the following pattern;

$records = array();
function myRecordHandler($record)
{
  global $records;
  $records[] = $record;
}
MagicParser_parse("http://www.example.com/feed1.xml","myRecordHandler","xml|RECORD/PATH/");
function myRecordHandler2($record2)
{
  global $record
  // here you have original $record and $record2 from second parse
}
foreach($records as $record)
{
  MagicParser_parse("http://www.example.net/feed2.asp?id=".$record["ID"],"myRecordHandler2","xml|RECORD/PATH/");
}

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by apienczy on Tue, 2012-09-11 16:50

Thank you; this is why I preferred to ask first instead of implementing recursive calls.

Best,
A