0

I am reading an XML to get the list of airport from IATA.

Below is the xml:

array ( 0 => SimpleXMLElement::__set_state(array( 'airport' => 'Aalborg, Denmark ', 'code' => 'AAL', )), 1 => SimpleXMLElement::__set_state(array( 'airport' => 'Aalesund, Norway ', 'code' => 'AES', )), 2 => SimpleXMLElement::__set_state(array( 'airport' => 'Aarhus, Denmark - Bus service ', 'code' => 'ZID', )))

I have tried:

$list = $xml->xpath("//airport");
display_output($list[0]);

I am getting:

SimpleXMLElement::__set_state(array( ))

How can I get?

Aalborg, Denmark
rfpdl
  • 956
  • 1
  • 11
  • 35

1 Answers1

0

The array is not the xml. Could you have a look at the xml-file at githubusercontent?

$ curl -s https://raw.githubusercontent.com/dodyg/AndroidRivers/master/assets/airports.xml | xmllint --xpath '//iata/iata_airport_codes[code="AAL"]' -
<iata_airport_codes>
        <airport>Aalborg, Denmark</airport>
        <code>AAL</code>
    </iata_airport_codes>

Below gives you your example output;

$ curl -s https://raw.githubusercontent.com/dodyg/AndroidRivers/master/assets/airports.xml | xmllint --xpath '//iata/iata_airport_codes[code="AAL"]/airport/text()' -
Aalborg, Denmark

To get the same result with PHP (get the first item of the array);

$airport = $xml->xpath('//iata/iata_airport_codes[code="AAL"]/airport/text()')[0];
echo $airport
Kokkie
  • 546
  • 6
  • 15
  • That is the same file which I have downloaded from IATA. when I used the xpath you are using $list = $xml->xpath('//iata/iata_airport_codes[code="AAL"]/airport/text()'); display_output($list); I am getting this: array ( 0 => SimpleXMLElement::__set_state(array( )), ) – rfpdl Jul 22 '14 at 06:01
  • That is because it returns an array, see http://stackoverflow.com/questions/16219060/array-to-string-conversion-notice-when-getting-variable-value-with-xpath – Kokkie Jul 22 '14 at 06:59