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.asmx/getAirportInformationByAirportCode?airportCode=MSP

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

    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;
}

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

http://www.webservicex.net/uszip.asmx/GetInfoByZIP?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:

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

  MSPMINNEAPOLIS INTLUnited StatesUS6361000084144540N93130W


    )

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

    )

)

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!

    7 days later
    scambro;11020897 wrote:

    because visually they look different when I load them into Chrome.

    Have you looked at the XML source for both documents?

      johanafm;11021205 wrote:

      Have you looked at the XML source for both documents?

      Not sure exactly what you mean. I did just look at the source in chrome (view source), but not sure what that told me. Thanks!

        Well, one should show things like < and > while the other shows things like <lt; and <gt;

          johanafm wrote:

          ...while the other shows things like <lt; and <gt;

          Wow, it's an XML document encoded as a string inside another XML document!

            I'm still struggling with this and am hopeful someone has an idea how I can parse this differently, or what is wrong with what I've currently tried. Thanks!

              As I said, one of them is an XML document encoded as a string inside another XML document (one of the sillier things I've seen recently). So you'd need to parse the XML document to get the string inside, then send that string through the XML parser again.

                Weedpacket;11021805 wrote:

                As I said, one of them is an XML document encoded as a string inside another XML document (one of the sillier things I've seen recently). So you'd need to parse the XML document to get the string inside, then send that string through the XML parser again.

                Aaaah, that's not what I understood from your post. I should be able to mess around with that in about an hour. Thanks for the direction!

                  scambro;11021817 wrote:

                  Aaaah, that's not what I understood from your post. I should be able to mess around with that in about an hour. Thanks for the direction!

                  That did it! Here's what I ended up doing, fyi:

                  $airportInfo = new GetAirportInfo(MSP);
                  $airportInfo->xmlobj = simplexml_load_string($airportInfo->xmlobj,'SimpleXMLElement');
                  

                  Seems to work, although I am still confused why I see two sets of data in the XML string, but I'm hoping that they never conflict...

                  Thanks!

                    Considering how they screwed up their XML document to begin with, I wouldn't really count on anything... However, it is probably still safe to assume that both matching elements actually do match. I.e. the airport code of both elements will match the airport code you searched for. If you assume this is safe, then you can simply disregard either of the elements. Should you deem that you cannot trust the search functionality, you'd simply iterate over the result until you reach the end (no match) or find a matching airport code. And in this case, you should always do this - even if only one airport would be returned.

                    Well, you could always compare the airport code for the two elements. If

                      Write a Reply...