You are here:  » Not displaying data


Not displaying data

Submitted by baggagepin on Thu, 2011-02-03 17:30 in

Hi,

I have a small issue when trying to display the data from an XML file I pass through the magicparser. I have tested it out on the MagicParser demo page and all is fine, I then generate the PHP code and place the in a script. When I run the script from the server I do not display the data concerned. I know I am doing something wrong but for the life of me I can not see what. Many thanks for any help you can give.

The PHP file generated is;

require("/var/www/vhosts/mydomain.com/httpdocs/MagicParser.php");
  function myRecordHandler($record)
  {
    // This is where you write your code to process each record, such as loading a database
    // You can display the record contents using PHP's internal print_r() function:
    print_r($record);
    // The following code will print out each field in your sample data:
    print $record["FLIGHTHISTORY"];
    print $record["FLIGHTHISTORY-DEPARTUREAIRPORTTIMEZONEOFFSET"];
    print $record["FLIGHTHISTORY-ARRIVALAIRPORTTIMEZONEOFFSET"];
    print $record["FLIGHTHISTORY-ACTUALAIRCRAFTTYPE"];
    print $record["FLIGHTHISTORY-ARRIVALDATE"];
    print $record["FLIGHTHISTORY-CREATORCODE"];
    print $record["FLIGHTHISTORY-DEPARTUREDATE"];
    print $record["FLIGHTHISTORY-DEPARTURETERMINAL"];
    print $record["FLIGHTHISTORY-FLIGHTHISTORYID"];
    print $record["FLIGHTHISTORY-FLIGHTNUMBER"];
    print $record["FLIGHTHISTORY-PUBLISHEDARRIVALDATE"];
    print $record["FLIGHTHISTORY-PUBLISHEDDEPARTUREDATE"];
    print $record["FLIGHTHISTORY-SCHEDULEDAIRCRAFTTYPE"];
    print $record["FLIGHTHISTORY-SCHEDULEDBLOCKTIME"];
    print $record["FLIGHTHISTORY-SCHEDULEDGATEARRIVALDATE"];
    print $record["FLIGHTHISTORY-SCHEDULEDGATEDEPARTUREDATE"];
    print $record["FLIGHTHISTORY-STATUS"];
    print $record["FLIGHTHISTORY-STATUSCODE"];
    print $record["AIRLINE"];
    print $record["AIRLINE-AIRLINECODE"];
    print $record["AIRLINE-IATACODE"];
    print $record["AIRLINE-ICAOCODE"];
    print $record["AIRLINE-NAME"];
    print $record["ORIGIN"];
    print $record["ORIGIN-AIRPORTCODE"];
    print $record["ORIGIN-IATACODE"];
    print $record["ORIGIN-ICAOCODE"];
    print $record["ORIGIN-NAME"];
    print $record["DESTINATION"];
    print $record["DESTINATION-AIRPORTCODE"];
    print $record["DESTINATION-IATACODE"];
    print $record["DESTINATION-ICAOCODE"];
    print $record["DESTINATION-NAME"];
  }
  MagicParser_parse("/var/www/vhosts/mydomain.com/httpdocs/xml/lhr_24_arrive.xml","myRecordHandler","xml|FLIGHTHISTORYGETRECORDSRESPONSE/FLIGHTHISTORY/");

The content of the XML file (short version):
 <?xml version="1.0" encoding="UTF-8" ?>
<FlightHistoryGetRecordsResponse xmlns="http://pathfinder-xml/FlightHistoryService.xsd">
<FlightHistory DepartureAirportTimeZoneOffset="0" ArrivalAirportTimeZoneOffset="1" ActualAircraftType="733" ArrivalDate="2011-02-03T21:45:00.000" CreatorCode="O" DepartureDate="2011-02-03T19:25:00.000" DepartureTerminal="1" FlightHistoryId="216186600" FlightNumber="3387" PublishedArrivalDate="2011-02-03T21:45:00.000" PublishedDepartureDate="2011-02-03T19:25:00.000" ScheduledAircraftType="733" ScheduledBlockTime="80" ScheduledGateArrivalDate="2011-02-03T21:45:00.000" ScheduledGateDepartureDate="2011-02-03T19:25:00.000" Status="Scheduled" StatusCode="S">
  <Airline AirlineCode="LH" IATACode="LH" ICAOCode="DLH" Name="Lufthansa" />
  <Origin AirportCode="LHR" IATACode="LHR" ICAOCode="EGLL" Name="Heathrow Airport" />
  <Destination AirportCode="DUS" IATACode="DUS" ICAOCode="EDDL" Name="Dusseldorf Airport" />
  </FlightHistory>
<FlightHistory DepartureAirportTimeZoneOffset="0" ArrivalAirportTimeZoneOffset="1" ArrivalDate="2011-02-03T15:30:00.000" ArrivalTerminal="" CreatorCode="O" DepartureDate="2011-02-03T12:40:00.000" DepartureTerminal="1" FlightHistoryId="216227293" FlightNumber="3407" PublishedArrivalDate="2011-02-03T15:30:00.000" PublishedDepartureDate="2011-02-03T12:40:00.000" ScheduledAircraftType="319" ScheduledBlockTime="110" ScheduledGateArrivalDate="2011-02-03T15:30:00.000" ScheduledGateDepartureDate="2011-02-03T12:40:00.000" Status="Scheduled" StatusCode="S">
  <Airline AirlineCode="BD" IATACode="BD" ICAOCode="BMA" Name="bmi" />
  <Origin AirportCode="LHR" IATACode="LHR" ICAOCode="EGLL" Name="Heathrow Airport" />
  <Destination AirportCode="DRS" IATACode="DRS" ICAOCode="EDDC" Name="Dresden Airport" />
  </FlightHistory>
<FlightHistory DepartureAirportTimeZoneOffset="0" ArrivalAirportTimeZoneOffset="5" ArrivalDate="2011-02-04T11:00:00.000" ArrivalTerminal="2" CreatorCode="O" DepartureDate="2011-02-03T20:25:00.000" DepartureTerminal="4" FlightHistoryId="216181381" FlightNumber="8" PublishedArrivalDate="2011-02-04T11:00:00.000" PublishedDepartureDate="2011-02-03T20:25:00.000" ScheduledAircraftType="330" ScheduledBlockTime="545" ScheduledGateArrivalDate="2011-02-04T11:00:00.000" ScheduledGateDepartureDate="2011-02-03T20:25:00.000" Status="Scheduled" StatusCode="S">
  <Airline AirlineCode="IT" IATACode="IT" ICAOCode="KFR" Name="Kingfisher" />
  <Origin AirportCode="LHR" IATACode="LHR" ICAOCode="EGLL" Name="Heathrow Airport" />
  <Destination AirportCode="BOM" IATACode="BOM" ICAOCode="VABB" Name="Chhatrapati Shivaji International Airport" />
  </FlightHistory>
</FlightHistoryGetRecordsResponse>

Sorry to be a pain.

Best regards,

Dereck

Submitted by support on Thu, 2011-02-03 17:40

Hi Dereck,

I wonder if it is a permissions issue. Where you have the following code in your script:

  MagicParser_parse("/var/www/vhosts/mydomain.com/httpdocs/xml/lhr_24_arrive.xml","myRecordHandler","xml|FLIGHTHISTORYGETRECORDSRESPONSE/FLIGHTHISTORY/");

Try REPLACEing that with:

  if (!MagicParser_parse("/var/www/vhosts/mydomain.com/httpdocs/xml/lhr_24_arrive.xml","myRecordHandler","xml|FLIGHTHISTORYGETRECORDSRESPONSE/FLIGHTHISTORY/"))
  {
    print MagicParser_getErrorMessage();
  }

Assuming that no error message is displayed, the next thing I would suspect might be a character encoding error. In this case, REPLACE the above code with the following:

  $xml = file_get_contents("/var/www/vhosts/mydomain.com/httpdocs/xml/lhr_24_arrive.xml");
  $xml = utf8_encode($xml); MagicParser_parse("string://".$xml,"myRecordHandler","xml|FLIGHTHISTORYGETRECORDSRESPONSE/FLIGHTHISTORY/");

What this will do is cleanse the data to valid UTF-8 which should do the trick...

Cheers,
David.

Submitted by baggagepin on Thu, 2011-02-03 18:02

Hi David,

Fixed.

$xml = file_get_contents("/var/www/vhosts/mydomain.com/httpdocs/xml/lhr_24_arrive.xml");
$xml = utf8_encode($xml); MagicParser_parse("string://".$xml,"myRecordHandler","xml|FLIGHTHISTORYGETRECORDSRESPONSE/FLIGHTHISTORY/");

The above did the trick.

Its been stated many times on this forum that you do provide great support. It's a pity that some of the big IT companies don't take a leaf out of your book, such a great job.

Many, many thanks.

Dereck