I'm looking at the Chicago Open Data Portal's list of bus stops, and I see that they've doubly-escaped some, but not all, of their ampersands. In other words, they sometimes encode their ampersands as &amp, and sometimes just as &
The pattern I notice is that they doubly-escape ampersands inside of the description fields, which are fully-fledged HTML documents inside of the KML document itself.
Does anyone have any insight on this? Is it a bug in the city data? It doesn't render correctly in Google Earth either.
The XML entity encoding in the Chicago Open Data Portal's list of bus stops in KML is incorrect.
The following KML snippet shows up as Indiana & 14th Street
in the description balloon of Google Earth not as "Indiana & 14th Street" which was intended.
Example:
<Placemark>
<name>Indiana & 14th Street</name>
<description>
<![CDATA[<html xmlns:fo="http://www.w3.org/1999/XSL/Format">
...
<td>PUBLIC_NAME</td>
<td>Indiana &amp; 14th Street</td>
....
</html>
]]>
</description>
The text &amp;
is decoded as &
which by using the CDATA block is shown as-is. To display the "&" in the description then a &
or &
(not both) is needed within the CDATA block content. The encoding in the name field is correct since it doesn't have a CDATA tag.
In fact, the KML should use a single BalloonStyle to capture the lengthy HTML text in each placemark with ExtendedData for specific values (e.g. city, status, public name, etc.) in the placemarks in addition to compressing the file as a KMZ -- this would greatly reduce the 15MB file to a much smaller size.
Here's a tutorial using BalloonStyles and ExtendedData.
https://developers.google.com/kml/documentation/extendeddata
Here's a description of special entity encoding in KML.
http://kml4earth.appspot.com/kmlErrata.html#encoding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With