Hello to everybody. I don't understand how to parse the image. I have the following schemas:
<merchant>
<product id="1323" number="4">
<affiliateprogram id="218322" />
<info>
<name>bla</name>
<description state="short">here the short description</description>
<description state="long">the long description</description>
</info>
<category />
<links>
<deeplink>http://www.site.ext/?id=2</deeplink>
<image state="medium">
<url>http://images.site.ext/images1.gif</url>
</image>
</links>
<state>1</state>
<date state="update">2007-08-08T11:42:00</date>
<offer>
<currentprice currency="EUR">9.95</currentprice>
</offer>
</product>
I was using this:
<?php
require("/MagicParser.php");
$records = array(); // global array of records to pick from later
MagicParser_parse("productdata.xml","myRecordHandler","xml|MERCHANT/PRODUCT/");
shuffle($records);
?>
<?php
$count = 0;
function myRecordHandler($record)
{
global $count;
echo '<p><img src='.$record["LINKS/URL"].' border=0 >'.$record["INFO/DESCRIPTION"].', '.$record["LINKS/URL"].' <br />';
echo 'Euro '.$record["OFFER/CURRENTPRICE"].''.$record["PRICE-CURRENCY"].' <a href="'.$record["LINKS/DEEPLINK"].'" target="_blank">Go</a></p>';
$count++;
if ($count == 25) return TRUE;
}
?>
but I cannot show the image. What is wrong?
Also, how to select "short" or "long" description?
Thank you very much
Thanks David for quick help, now it works perfectly :-)
A question: where to put the trick
print_r($record);
exit();
?
Hi,
You would just put that right inside myRecordHandler(), for example:
<?php
function myRecordHandler($record)
{
print_r($record);
exit();
}
?>
This will show you what is in $record!
Cheers,
David.
Hi,
From studying the XML in your post, for the image you need to use:
$record["LINKS/IMAGE/URL"]
...and for the different descriptions, the second description in the feed will be differentiated using @1, so you need to use:
$record["INFO/DESCRIPTION@1"]
Don't forget the print_r($record) trick if you want to see what is being passed to myRecordHandler(); for example:
print_r($record);
exit();
Hope this helps!
Cheers,
David.