Google Earth KML Invalid

By Xah Lee. Date:

This article documents a condition of a software industry. It is a rant on software correctness and standards body responsibility.

So, today i'm working on KML files on my site again. KML file is a XML file used for Google Earth .

For example, a typical KML file on my site looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Placemark>
<name>Aapua wind park</name>
<description>
Good for a visit.

Seven 80 meter high wind turbines.

See photos at:
 http://xahlee.org/Whirlwheel_dir/windturbine.html
</description>
<Point><coordinates>23.436459,66.827370</coordinates></Point>
<LookAt>
 <longitude>23.436459</longitude>
 <latitude>66.827370</latitude>
 <altitude>0</altitude>
 <range>10000</range>
 <tilt>0</tilt>
 <heading>0</heading>
</LookAt>
</Placemark>
</kml>

I'm a correctness nerd. So when i started to add KML files on my website, i made sure that the KML files i created are correct. I spend several hours reading Google Earth's KML tutorial, and reading Wikipedia on KML about it, figure out the correct DTD, which tags are required, and typically also spend considerable time to figure out what optional tag or choice of formatting that i personally would use. I know, for a certainty, that the format i created to be used on my site is strictly correct.

However, i don't remember that i've ever used a KML validator to verify whether my KML files pass. I'm certain i've tried to find it. I think at the time (this is in 2006), there is no readily available KML validators, only generic XML validators. In any case, so today i quickly found a authoritative KML validator at http://www.kmlvalidator.com/home.htm. And, boom, it says my files are invalid.

The first error is:

This does not appear to be an OGC KML document--expected document element in namespace "http://www.opengis.net/kml/2.2", but found: "http://earth.google.com/kml/2.2"

What the faak?

The second error is:

cvc-complex-type.2.4.a: Invalid content was found starting with element 'tilt'. One of '{"http://www.opengis.net/kml/2.2":altitudeModeGroup, "http://www.opengis.net/kml/2.2":LookAtSimpleExtensionGroup, "http://www.opengis.net/kml/2.2":LookAtObjectExtensionGroup}' is expected.

I'm sure that i followed tutorial example from the Google dragon's mouth carefully. So i went to Google Earth's KML tutorial again, at: [ http://code.google.com/apis/kml/documentation/kml_tut.html ] The string http://earth.google.com/kml/2.2 is now nowhere to be found there. Apparently, they changed it. Also, the few pages of the tutorial do not contain any <tilt> or <LookAt> tag.

Who Listens to Correctness When Authorities Meander?

Apparently, thru the years, as tech and software progressed, they made changes and fixed things, as usual. But the point here is, today a working programer has to know tens of protocols, formats, and multiple languages, and if the programer paid attention to detail in the spec, and later be faaked in the face for his efforts to follow spec, then why should we listen to any “recommendations”, “advices”, “specs” these standards bodies are giving out?

When XML and XHTML came alone in about 2000 with massive fanfare, we are told that XHTML will change society, or, at least, make the web correct and valid and far more easier to develop and flexible. Now it's a decade later. Sure the web has improved, but as far as html/xhtml and browser rendering goes, it's still a tag soup with extreme complexities. 99.99% of web pages are still not valid. Major browsers still don't agree on their rendering behavior. Web dev is actually far more complex than before, involving tens or hundreds of tech that hardly a professional web developer have heard of (diverse languages, libraries, tools). It's hard to say if it is better at all than the HTML3 days with “font” and “table” tags and gazillion tricks. The best practical approach is still trial and error with browsers.

And, now HTML5 comes alone, from a newfangled hip group, with a attitude that validation is overrated — a flying faak to the face about the XML mantra from standards bodies, just when there starts to be more and more sites with correct XHTML.

XML is break from SGML, with many justifications why it needs be, and now HTML5 is a break from both SGML and XML. WTFML anyone?


PS The story of my KML above is actually slightly simplified. When i started to create KML files in 2006, Google's tutorial says:

<kml xmlns="http://earth.google.com/kml/2.1">

But in around 2008, when i was working on KML again, i noticed that the version is not 2.1 anymore but 2.2, and i think the Google tutorial for a simple file start to contain the <LookAt> tag, like this:

 <LookAt>
 <longitude>23.436459</longitude>
 <latitude>66.827370</latitude>
 <altitude>0</altitude>
 <range>10000</range>
 <tilt>0</tilt>
 <heading>0</heading>
 </LookAt>

I don't remember if it became required tag or not, or if a KML 2.2 file without this tag will simply not have the old behavior in Google Earth. Or, perhaps i got the idea of this block by looking at the many (now thousands) existing KML files in Google Earth.

I spent a hour or two to add this block into my existing ~65 KML files and modified my elisp code that generate KML files. (it takes 5 min to do the find replacement and modify my lisp code, but 1 hour to make a decision.) I wouldn't have done it if it wasn't important. Now, it all changed again, and this block is no longer shown in the simple example of Google Earth tutorial. Spent about 4 hours on this today, updating my site and research into this issue, not counting writing this article.

For emacs lisp code that generates KML files, see: Emacs Lisp: Writing a google-earth Function .