I have an XML file, (see below) that has an undefined number of "photo" fields.
Each entry has a different number of photos.
I know that magicparser will parse them as PHOTOS/PHOTO@1 etc.
How can I get a count of those entries and only process the ones I know exist?
Sample XML
<?xml version="1.0" encoding="UTF-8" ?>
<my_feed company_id="ID">
<listings>
<property>
<propid>1234</propid>
<photos>
<photo>1234a.jpg</photo>
<photo>1234b.jpg</photo>
<photo>1234c.jpg</photo>
<photo>1234d.jpg</photo>
<photo>1234e.jpg</photo>
<photo>1234f.jpg</photo>
</photos>
</property>
<property>
<propid>5678</propid>
<photos>
<photo>5678a.jpg</photo>
<photo>5678b.jpg</photo>
</photos>
</property>
</listings>
</my_feed>
Thanks! That worked great.
Your product has saved me hours of work!
Hello Dan,
The easiest way to handle this style of nested XML within your record handler function is to use a foreach() loop and inspect the key name, and then handle the value if it begins PHOTO/PHOTO, for example (non complete):
<?php
function myRecordHandler($record)
{
foreach($record as $key => $value)
{
if (strpos($key,"PHOTOS/PHOTO") === 0)
{
print $value;
}
}
}
?>
(of course you would do something different with $value, but that's the general idea!)
Hope this helps,
Cheers,
David.