You are here:  » Autodetect failed


Autodetect failed

Submitted by peter on Tue, 2007-07-17 09:09 in

Hello,

i've purchased your parser and it's excellent.
Recently i had to parse a xml file wich looks correct but does not parse.
It returns an "autodetect failed" error.

I use the format string "xml|PROPERTIES/PROPERTY/"

Can you help me?
Thank you very much.
Peter.

Below an example of the xml :

  <?xml version="1.0" encoding="iso-8859-1"?>
- <properties>
- <property>
  <propertyId>114</propertyId>
  <propertyReference>84HB00100</propertyReference>
  <propertySalestate>Verkocht onder voorbehoud</propertySalestate>
  <propertyType>Appartement</propertyType>
  <propertyConstructiontype>Nieuwbouw</propertyConstructiontype>
  <propertyConstructionyear>2007</propertyConstructionyear>
  <propertyCondition>Uitstekend</propertyCondition>
  <propertyPosition>Geschakeld</propertyPosition>
  <propertyLocation>Aan zee;Aan golfbaan</propertyLocation>
  <addressStreet>34, Paseo del Mar</addressStreet>
  <addressPostalcode>03590</addressPostalcode>
  <addressCity>Los Alcázares</addressCity>
  <addressArea>Costa Cálida</addressArea>
  <addressDistrict>Murcia</addressDistrict>
  <addressRegion>Murcia</addressRegion>
  <addressCountry>Spanje</addressCountry>
  <propertyBedrooms>2</propertyBedrooms>
  <propertyBathrooms>1</propertyBathrooms>
  <propertySurface>84</propertySurface>
  <propertyPlotsize>84</propertyPlotsize>
  <priceType>Vrij op naam</priceType>
  <priceVisibility />
  <priceCurrency>EUR</priceCurrency>
  <priceAmount>119.800</priceAmount>
- <propertytexts>
  <propertytextLanguage>NL</propertytextLanguage>
  <propertytextTitle>Appartementen Jardines de Alhama</propertytextTitle>
  <propertytextPreviewdescription>Diverse appartementen op resort 'Jardines de Alhama' in omgeving Mar Menor - Murcia.</propertytextPreviewdescription>
  <propertytextFulldescription>De appartementen op Jardines de Alhama zijn midden in de prachtige groene tuinen van het resort gelegen. Het resort is onderdeel van Condado de Alhama met Jardines de Alhama, Cortijos de Alhama en Naranjos de Alhama. Het gehele resort is voetgangersgebied. Er zijn fietspaden en grote open gebieden om heerlijk een wandeling te maken. In het midden van elk park is een zwembad gelegen welke perfect past bij bij de natuurlijke omgeving. Ook is er een speelterrein, zodat kinderen en hun ouders plezier kunnen maken. De Jardines de Alhama appartementen zijn verdeeld in gebouwen met 2 verdiepingen volgens traditionele Mediterraanse architectuur. De begane grond appartementen hebben terrassen op de hoogte van de tuin, met behoud van privacy van de woning en een subtiele overgang met de mooie omgeving. De appartementen op de verdieping hebben zowel een terras als een ruim dakterras. De top kwaliteit appartementen hebben 1 badkamer en 2 of 3 slaapkamers. Jardines de Alhama Golf resort heeft haar eigen, exclusieve Town Centre: El Foro, met vele vrijetijds en sportvoorzieningen.</propertytextFulldescription>
  </propertytexts>
- <mediafiles>
  <mediafileType>image</mediafileType>
  <mediafilePathMedium>http://www.evdr.nl/files/formattachments/Image/HousePictures/Foto_LQG_exterieur_1.JPG</mediafilePathMedium>
  <mediafilePathThumbnail>http://www.evdr.nl/files/formattachments/Image/HousePictures/Foto_LQG_exterieur_1_klein.jpg</mediafilePathThumbnail>
  <mediafileType>image</mediafileType>
  <mediafilePathMedium>http://www.ireos.eu/images/n/1175858670.jpg</mediafilePathMedium>
  <mediafilePathThumbnail />
  <mediafileType>image</mediafileType>
  <mediafilePathMedium>http://www.ireos.eu/images/n/1175858700.jpg</mediafilePathMedium>
  <mediafilePathThumbnail>http://www.ireos.eu/images/s/1175858700.jpg</mediafilePathThumbnail>
  </mediafiles>
  </property>
  </properties>

Submitted by support on Tue, 2007-07-17 09:13

Hello Peter,

If you are using a format string, Magic Parser does not use the autodetect logic, so you should not be getting this error.

Could you post an example of your code and i'll check it over for you? If you don't want to post it on the forum, feel free to email it to me - reply to your forum registration email or reg code email is the easiest way to get me..

Cheers,
David.

Submitted by peter on Tue, 2007-07-17 09:26

Thanks David.

Below the code i use to parse the file:

Regards,
Peter.

<?php
  
require("MagicParser.php");
  
$filename "ireos.xml";
  
$format_string MagicParser_getFormat($filename);
  if (!
$format_string)
  {
    print 
"<p>".MagicParser_getErrorMessage()."</p>";
    exit;
  }
  else
  {
    print 
"<p><strong>Autodetected Format String:</strong> ".$format_string."</p>";
  }
  print 
"<p>Contents of first record:</p>";
  function 
myRecordHandler($record)
  {
    print 
"<table border='0'>";
    foreach(
$record as $key => $value)
    {
      print 
"<tr>";
      print 
"<td>".$key."</td>";
      print 
"<td>".htmlentities($value)."&nbsp;</td>";
      print 
"</tr>";
    }
    print 
"</table>";
    
// return a non-zero value to stop reading any more records
    
return 1;
  }
  
MagicParser_parse($filename,"myRecordHandler","xml|PROPERTIES/PROPERTY/");
?>

Submitted by support on Tue, 2007-07-17 09:31

Hello Peter,

Autodetect is most likely failing because there are not enough of the main repeating record in the feed. However, as you are not relying on the result of the autodetect but instead using your own correct format string, simply remove that first section of code. All you need is this:

<?php
  
require("MagicParser.php");
  
$filename "ireos.xml";
  print 
"<p>Contents of first record:</p>";
  function 
myRecordHandler($record)
  {
    print 
"<table border='0'>";
    foreach(
$record as $key => $value)
    {
      print 
"<tr>";
      print 
"<td>".$key."</td>";
      print 
"<td>".htmlentities($value)."&nbsp;</td>";
      print 
"</tr>";
    }
    print 
"</table>";
    
// return a non-zero value to stop reading any more records
    
return 1;
  }
  
MagicParser_parse($filename,"myRecordHandler","xml|PROPERTIES/PROPERTY/");
?>

Cheers,
David.

Submitted by peter on Tue, 2007-07-17 09:47

Hello David,

you are right, the error is gone, thank you.
I've changed the code to test the fields with the code below but does not return a result.
As you suggested i've tried to read a larger feed with 2 properties, the result is empty.
Any ideas?

Thank you very much for your help.
Peter.

*table*

<?php
  
require("MagicParser.php");
  function 
myRecordHandler($item) {
    echo 
"<tr>";
    echo 
"<td>".$item["PROPERTYID"]."</td>";
    echo 
"<td>".$item["PROPERTYREFERENCE"]."</td>";
    echo 
"</tr>";
  }
  
$url "ireos.xml";
  
MagicParser_parse($url,"myRecordHandler","xml|PROPERTIES/PROPERTY/");
?>

*/table*

Submitted by support on Tue, 2007-07-17 10:01

Hello Peter,

Your code looked fine - and I just tested it with your example XML. Here is the output:

http://www.magicparser.com/examples/ireos.php

To test this I saved a copy of your sample XML from above - which is here:

http://www.magicparser.com/examples/ireos.xml

Here's the source:

<?php
  
require("MagicParser.php");
  print 
"<table border='1'>";
  function 
myRecordHandler($item) {
    echo 
"<tr>";
    echo 
"<td>".$item["PROPERTYID"]."</td>";
    echo 
"<td>".$item["PROPERTYREFERENCE"]."</td>";
    echo 
"</tr>";
  }
  
$url "ireos.xml";
  
MagicParser_parse($url,"myRecordHandler","xml|PROPERTIES/PROPERTY/");
  print 
"</table>";
?>

If this doesn't help please feel free to email me the original XML document and i'll make sure it works OK with the full feed...

Hope this helps!
David.

Submitted by peter on Tue, 2007-07-17 10:17

Thank you very much David!
You are right, i apologize, it did work except a stupid mistake i made with copy/paste extra properties.

Thanks again for your time and help :)
Regards,
Peter.