Simplexml_load_string not parsing XML

I posted this question over on phpbuilder, a few days ago, but haven’t had much luck getting ideas, so thought I’d try another forum as well. Any tips are appreciated!

Hello,

I think this is an error with the XML that’s being produced, because visually they look different when I load them into Chrome. Here’s the site that I’m having issues loading:

http://www.webservicex.net/airport.a...irportCode=MSP

In my php code, I’m using something like this:

[php]
public function load() {
if($this->airport) {
$url = “http://www.webservicex.net/airport.asmx/getAirportInformationByAirportCode?airportCode={$this->airport}”;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        $result = curl_exec($ch);

        curl_close($ch);

        $this->xmlobj = simplexml_load_string($result);
    }
}

public function __get($name) {
    return $this->xmlobj->Table->$name;
}

[/php]

I have the same code from the same provider, with a different XML request that works just fine:

http://www.webservicex.net/uszip.asm...IP?USZip=97219

The difference that I see is that everything is duplicated on the first link. I’m wondering if that’s the issue because when I go looking for GMToffset, there are two that qualify and it doesn’t know what to do. Is that a valid assumption? Is there an easy way to work around that? When I echo out the XML strings of these two responses they look like this:

[php]
GetAirportInfo Object
(
[airport] => MSP
[xmlobj] => SimpleXMLElement Object
(
[0] =>
MSPMINNEAPOLIS INTLUnited StatesUS6361000084144540N93130W

MSPMINNEAPOLIS INTLUnited StatesUS6361000084144540N93130W

    )

)
[/php]

[php]
GetInfoByZIP Object
(
[zip] => 97219
[xmlobj] => SimpleXMLElement Object
(
[table][tr][td] => SimpleXMLElement Object
(
[CITY] => Portland
[STATE] => OR
[ZIP] => 97219
[AREA_CODE] => 503
[TIME_ZONE] => P
)

    )

)
[/php]

Obviously that second one looks way more like what I’m expecting and I can then move through the different nodes and pull out values like city, state, etc. This is my first foray into using curl and xml to retrieve data, so I’m learning as I go along. Thanks for any suggestions![/td][/tr][/table]

Sponsor our Newsletter | Privacy Policy | Terms of Service