You are here:  » xml feeds whit different classification

Support Forum



xml feeds whit different classification

Submitted by wouter on Tue, 2007-12-04 16:33 in

Hi,

I have made to a script that reads xml product feeds into a mysql databse. have only 1 big qeustion.

<?php
print $record["CATEGORIES/CATEGORY-NAME"];
print 
$record["CATEGORIES/CATEGORY-PATH"];
?>

Some times has de var $record["CATEGORIES/CATEGORY-NAME"] the value land. And later in the same feed or in a other feed i find in the $record["CATEGORIES/CATEGORY-NAME"] the price....

Is there some who know how i can fix this nice ? I have now a fic whit some if's but now i have to make a if stament for al the feeds who are different.

regards
Wouter

Submitted by support on Tue, 2007-12-04 16:52

Hello Wouter,

If it is sometimes one and sometimes the other, then an IF statement is really all you can do, as it sounds like this is down to the person who is making the feed. If you want to post a bit more of the code that you have at the moment, that will help me understand better what you want to do and I might be able to see a better way...

Cheers,
David.

Submitted by wouter on Tue, 2007-12-04 17:14

This piece of code is that i can fix that i can enter the right country name in the database. But i think i do it to diffcult.

<?php
function Insert_feed($record)
{
  global 
$aanbieder_id;
  if (
$record['ADDITIONAL/FIELD@5-NAME'] == "land1")
  {
    
$land $record['ADDITIONAL/FIELD@5-VALUE'];
    
$check "1";
  }
  if (
$record['ADDITIONAL/FIELD@1-NAME'] == "land" OR $record['ADDITIONAL/FIELD@1-NAME'] == "city")
  {
    
$land $record["ADDITIONAL/FIELD@1-VALUE"];
    
$check "1";
  }
  if (
$check != "1")
  {
    
$land $record["ADDITIONAL/FIELD-VALUE"];
  }
  if (
$land == "")
  {
    
$error "1";
  }
  if (
$error != "1")
  {
     ...
?>

Submitted by support on Tue, 2007-12-04 17:31

Hi,

I think I can see what you are trying to do, and yes there probably is an easier way to do this. Can you post an example record (just 1) of the XML so that I can take a look?

Cheers,
David.

Submitted by wouter on Tue, 2007-12-04 18:24

I post two example records so you can see the diffrents...

example record 1

  <?xml version="1.0" encoding="utf-8" ?>
  <!DOCTYPE products (View Source for full doctype...)>
- <products>
- <product>
  <productID>bd3b0493524ff2be9affd1f93d99a60186608190</productID>
  <name>Zuidelijk Afrika : Overland van Kaapstad naar Victoria Falls, 29-daagse reis</name>
  <price currency="EUR">2695.00</price>
  <productURL>http://www.sawadee.nl/verrereis/?tt=864_0_12033_&r=http%3A%2F%2Fwww.sawadee.nl%2Freisroutes%2Ftoon_reis.php%3Frc%3DZUA%26tradetracker</productURL>
  <imageURL>http://www.sawadee.nl/reisroutes/images/zu01.jpg</imageURL>
- <description>
- <![CDATA[ Deze reis biedt een ongeëvenaarde variëteit aan landschappen en culturen: van het moderne Kaapstad tot het olifantrijke Chobe Park, van de surrealistische Namib tot het natuurgeweld van de Victoria watervallen, wandelen in de bosrijke Cederbergen en per mokoro door de Okavango Delta. Ook de Sossusvlei, met zijn huizenhoge zandduinen, zal enorme indruk maken.
  ]]>
  </description>
  <categories />
- <additional>
  <field name="boekbaar" value="ja" />
  <field name="vertrekdatum" value="2008-09-06" />
  <field name="terugkomstdatum" value="2008-10-04" />
  <field name="aantaldagen" value="29" />
  <field name="regio" value="Afrika" />
  <field name="land1" value="Zuid-Afrika" />
  <field name="land2" value="Botswana" />
  <field name="land3" value="Namibie" />
  <field name="land4" value="Zambia" />
  <field name="merk" value="Sawadee" />
  <field name="dag1" value="Route 29-daagse reis:" />
  <field name="dag2" value="Dag 01 vlucht naar Kaapstad met KLM" />
  <field name="dag3" value="Dag 02-03 Kaapstad" />
  <field name="dag4" value="Dag 04-05 Cederbergen" />
  <field name="dag5" value="Dag 06 Oranjerivier" />
  <field name="dag6" value="Dag 07 Fish River Canyon" />
  <field name="dag7" value="Dag 08-09 Namibrand" />
  <field name="dag8" value="Dag 10-11 Sossusvlei" />
  <field name="dag9" value="Dag 12-13 Swakopmund" />
  <field name="dag10" value="Dag 14-15 Damaraland" />
  <field name="dag11" value="Dag 16-18 Etosha" />
  <field name="dag12" value="Dag 19-21 Popa Falls, Okavango Delta" />
  <field name="dag13" value="Dag 22-24 Caprivi, Chobe" />
  <field name="dag14" value="Dag 25-27 Victoria Falls" />
  <field name="dag15" value="Dag 28 vlucht naar Amsterdam via Johannesburg" />
  <field name="dag16" value="Dag 29 aankomst Amsterdam" />
  <field name="steden" value="Kaapstad, Cederbergen, Oranjerivier, Fish River Canyon, Namibrand, Sossusvlei, Swakopmund, Damaraland, Etosha, Popa Falls, Okavango Delta, Caprivi, Chobe, Victoria Falls, Johannesburg" />
  <field name="verschil1" value="Vier dagen Namibwoestijn en drie nachten Etosha" />
  <field name="verschil2" value="Wandelen in de bosrijke Cederbergen" />
  <field name="verschil3" value="Wildkamperen bij de Spitzkoppe" />
  <field name="verschil4" value="Kleine groepen van 10-18 personen" />
  </additional>
  </product>

example record 2

<?xml version="1.0" encoding="utf-8" ?>
  <!DOCTYPE products (View Source for full doctype...)>
- <products>
- <product>
  <productID>cc577a790ac8bd2c482308a45b9c6f25ae863a0d</productID>
  <name>Australië</name>
  <price currency="EUR">2899.00</price>
  <productURL>http://www.shoestring.nl/tradetracker/?campaignID=159&materialID=0&affiliateID=12033&redirectURL=http%3A%2F%2Fwww.shoestring.nl%2Fwww%2Findex.php%3Fm%3Dbrochure%26reiscode%3DGRSSAU</productURL>
  <imageURL>http://www.shoestring.nl/www/images/brochure_images/GRSSAU_2.jpg</imageURL>
- <description>
- <![CDATA[ Ga mee op deze avontuurlijke ontdekkingsreis en maak kennis met dit woeste, ongerepte land. Zwijmel weg bij de prachtigste witte zandstranden, ga op zoek naar de unieke flora en fauna en geniet! Avontuurlijk kan het zeker worden: bungee jumping, kameelrijden, ballonvaren, duiken of snorkelen. Het is allemaal mogelijk. Dit is een reis voor reizigers die niet schromen om onder primitieve omstandigheden te overnachten, in tenten of onder de sterrenhemel.
  ]]>
  </description>
- <categories>
  <category name="groepsreis" path="groepsreis" />
  </categories>
- <additional>
  <field name="land" value="Australie" />
  </additional>
  </product>

Submitted by support on Wed, 2007-12-05 09:42

Hi,

In the second example, I assume you just want land=Australie

But, in the first example, what do you want?

Do you want just the first land, so land=Zuid-Afrika, or do you want more?

Cheers,
David.

Submitted by wouter on Wed, 2007-12-05 13:43

The problem is. That in example 1 has the country name and in example 2 . So the problem is that the field names are different. Whit that if i posted first i fix it that the country names come on the right place in the db.

Submitted by support on Wed, 2007-12-05 13:45

Hello wouter,

In the second example, is it just the first country name you want?

Cheers,
David.

Submitted by wouter on Wed, 2007-12-05 15:58

Hello David,

Yes for now i need only the first country.

Submitted by support on Wed, 2007-12-05 16:21

Hello wouter,

Here is one way to do it. You scan through all the fields, looking for the first field name that starts "FIELD" and the value starts "land". Then, you take the next value. Here is the code:

<?php
  
function myRecordHandler($record)
  {
    
// get the first land value
    
foreach($record as $k => $v)
    {
      if (
$found) { $land $v; break; }
      if ((
strpos($k,"FIELD")===0)&&(strpos($v,"land")===0)) $found true;
    }
    print 
$land."\n";
  }
?>

Hope this helps!
Regards,
David.

Submitted by wouter on Fri, 2007-12-07 07:39

Hello David,

Sorry for my late reply! I'm a bit to busy...

This solution looks great! I will test it Sunday. When i gave problems i will post it.

Thanks!

Greets Wouter

Submitted by wouter on Fri, 2007-12-07 08:25

Hello David,

I have trying the code, but he don't give back a land name.

I have read about strpos() on php.net but i don't see whats wrong!

My testing file is now.

<?php
require("includes/MagicParser.php");
  function 
myRecordHandler($record)
  {
    
// get the first land value
    
foreach($record as $k => $v)
    {
      if (
$found) { $land $v; break; }
      if ((
strpos($k,"FIELD")===0)&&(strpos($v,"land")===0)) $found true;
    }
    print 
$land."\n";
  }
  
MagicParser_parse("{link saved}","myRecordHandler","xml|PRODUCTS/PRODUCT/");
?>

Maybe you have a idea whats wrong ?

Greest Wouter

P.S. please remove the xml url.

Submitted by support on Fri, 2007-12-07 09:14

Hello Wouter,

Almost there! In my test version the fields begain with FIELD, not ADDITIONAL/FIELD, so you just need to add that. Try this version (your xml url removed):

<?php
  
require("includes/MagicParser.php");
  function 
myRecordHandler($record)
  {
    
// get the first land value
    
foreach($record as $k => $v)
    {
      if (
$found) { $land $v; break; }
      if ((
strpos($k,"ADDITIONAL/FIELD")===0)&&(strpos($v,"land")===0)) $found true;
    }
    print 
$land."\n";
  }
  
MagicParser_parse("{link saved}","myRecordHandler","xml|PRODUCTS/PRODUCT/");
?>

The only change is from "FIELD" to "ADDITIONAL/FIELD" on line 9.

Hope this helps!
Regards,
David.

Submitted by wouter on Fri, 2007-12-07 10:50

Hello David,

Stupid me! I think strpos() looking for FIELD zo he didn't need the hole name. That's why i didn't understand why it was not working.

I will try this sunday because i can't test it now.

Tanks!

Greets Wouter

Submitted by wouter on Wed, 2007-12-12 10:50

Hi David,

Sorry for my late reply! But i'm sometime i'm to busy...

The foreach loop you give work great! I have modified it a bit so i does now exactly what i need!

Thanks for you're fast and very good support!

regards Wouter