Monday, March 2, 2009

Parsing KML with ActionScript XML e4x

I spent some time trying to figure out why I could not get the ActionScript XML object to properly parse a KML file and found out that the problem was in the namespace of the KML. KML sets its global namespace to whichever version of KML you are using. The problem is that when you try to access the tags using the e4x methods it does not work. So to fix the problem you need to then set the default namespace.
default xml namespace = new Namespace("http://www.opengis.net/kml/2.2");

3 comments:

  1. It is important to note that you must use the namespace mentioned in the xmlns declared in the KML that you are trying to parse.

    Thanks for the tip, this saved me hours of debugging!

    ~jookyone

    ReplyDelete
  2. THANK YOU!!
    I couldn't figure out why my KML parsing wasn't working. I spent a whole day debugging until I found your site.

    ReplyDelete
  3. Wow. A full 4 years after you posted this, it's still rescuing people like me who couldn't understand why their KML parse was failing.

    Thanks so much!

    ReplyDelete