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 
0

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

2 Comments

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( )), )
That is because it returns an array, see stackoverflow.com/questions/16219060/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.