Debugging KML file

13,427

There are a handful of techniques you can apply to debug and repair a corrupt KML file.

Basically, the quickest way to validate a KML file is first using your web browser. KML is an XML file so first you can test if it's a well-formed XML file, which is a prerequisite to it being a valid KML file. Simply rename the KML file adding an .xml file extension then drag the file onto a web browser (Firefox, Chrome, etc.) to validate it. See detailed example here.

Once those errors are found and fixed then you can try a KML validator that checks if the file is valid KML with respect to the OGC KML Specification and associated XML Schema such as the standalone command-line XmlValidator tool.

In your example, if you run it through a simple XML SAX parser it shows: element type "br" must be terminated by the matching end-tag "</br>" at column 455.

Error being that <description> element has HTML markup but isn't escaped with a CDATA block (CDATA is part of the XML standard). To fix this you need to reformat your KML like this:

  <description>
      <![CDATA[
          <b>Project Information</b>
          ...
          <br>
      ]]>
  </description>

Also, the element has the wrong name (Description vs description). KML is case-sensitive.

More tips to debug KML files can be found here.

Share:
13,427
user1863848
Author by

user1863848

Updated on June 04, 2022

Comments

  • user1863848
    user1863848 almost 2 years
    <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">
    <Document> <Placemark> <Name>Test Name</Name> <Description><b>Project Information</b><br><ul><li>Project Name: Test Name</li><li>Project Number: Test Number</li><li>Project Location:  Test Location</li><li>System: Test System</li></ul><br><b>Project Team</b><br><br><ul><li>Regional Manager: Mem 1</li><li>Project Manager: Mem 2</li></ul><br>YouTube Video URL: <a href="http://youtu.be/U9EYP9GIe2k"><br>Picassa Album URL: <a href="www.picassa.com"><br></Description> <Point> <Coordinates>30,-125</Coordinates>,0 </Point> </Placemark> </Document> </kml>
    

    This is what my custom Excel macro is generating (I'm new to programming, so take it easy on me if you notice something big). When I attempt to open the KML file with Google Earth, I get the following message: Open of file "file path" failed: Parse error at line 2, column 454: mismatched tag. This correlates to the /Description tag... What is wrong with this tag? I matches up with it's corresponding Description tag.

  • user1863848
    user1863848 over 11 years
    Thanks for the heads up, Jason. My issue is that I'm stuck in the initial part of your validation process - testing if it's a well-formed XML file. When I open the file in Chrome, the error is in the same location as what GE gives me: the </Description> tag. When I copy/paste my code into Notepad++ it says that my tags match, but is opposite of what Chrome/GE are telling me.
  • user1863848
    user1863848 over 11 years
    Thanks, Jason. I did not know about CDATA, so I appreciate you taking a look and helping me out. Everything works well now!