Gosman
asked on
simplexml_load_string() Problem
I've attached the code I am using. I am expecting the following result
Hoover Dam
Helicopter Flights
The London Eye
The 02
Empire State Building
The Statue Of Liberty
What I'm actually getting is
Hoover Dam
Helicopter Flights
Help really appreciated.
Hoover Dam
Helicopter Flights
The London Eye
The 02
Empire State Building
The Statue Of Liberty
What I'm actually getting is
Hoover Dam
Helicopter Flights
Help really appreciated.
<?php
$xmlcontent='<?xml version="1.0" encoding="UTF-8"?>
<ResultSet size="3">
<Destination name="Las Vegas area, NV" order="1">
<ListResults size="2">
<Attraction order="1">
<name><![CDATA[Hoover Dam]]></name>
</Attraction>
<Attraction order="2">
<name><![CDATA[Helicopter Flights]]></name>
</Attraction>
</ListResults>
</Destination>
<Destination name="London, GBR" order="2">
<ListResults size="2">
<Attraction order="1">
<name><![CDATA[The Londo Eye]]></name>
</Attraction>
<Attraction order="2">
<name><![CDATA[The 02]]></name>
</Attraction>
</ListResults>
</Destination><Destination name="New York, NY" order="3">
<ListResults size="2">
<Attraction order="1">
<name><![CDATA[Empire State Building]]></name>
</Attraction>
<Attraction order="2">
<name><![CDATA[The Statue Of Liberty]]></name>
</Attraction>
</ListResults>
</Destination>
</ResultSet>';
$xml = simplexml_load_string($xmlcontent);
foreach ($xml->Destination->ListResults->Attraction as $attraction)
{
$name.=$attraction->name."<br/>";
}
echo "$name";
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Both worked. I went with bportlock as best solution as it required less code and also highlighted xpath which I knew nothing about.