Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using both & and amp; to represent ampersand in KML?

Tags:

kml

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.

like image 678
szxk Avatar asked Nov 01 '22 20:11

szxk


1 Answers

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 &#38; 14th Street</name>
    <description>
      <![CDATA[<html xmlns:fo="http://www.w3.org/1999/XSL/Format">
        ...
        <td>PUBLIC_NAME</td>
        <td>Indiana &#38;amp; 14th Street</td>
        ....
       </html>
      ]]>
    </description>

The text &#38;amp; is decoded as &amp; which by using the CDATA block is shown as-is. To display the "&" in the description then a &#38; or &amp; (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

like image 188
CodeMonkey Avatar answered Jan 04 '23 13:01

CodeMonkey