Search code examples
xmlkmlgoogle-earth

KML document works, but when written programatically, the encoding is wrong?


<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
    <name>cwvtrial.kml</name>
    <Placemark>
        <name>PawneeNationalGrasslandBirdingLoop</name>
        <Point>
            <coordinates>-104.336274,40.642254,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>PawneeButtes</name>
        <Point>
            <coordinates>-104.00072,40.814517,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>TamarackRanchStateWildlifeArea</name>
        <Point>
            <coordinates>-102.804758,40.822466,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>RedLionJumboReservoirStateWildlifeArea</name>
        <Point>
            <coordinates>-102.669417,40.896904,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>PrewittReservoirStateWildlifeArea</name>
        <Point>
            <coordinates>-103.328779,40.430521,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>JacksonLake</name>
        <Point>
            <coordinates>-104.096527,40.391156,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>SouthPlatteRiverEagleDrivingTour</name>
        <Point>
            <coordinates>-103.826038,40.266986,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>GreaterPrairieChickenLeks</name>
        <Point>
            <coordinates>-102.219793,40.238643,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>BonnyLakeStateParkSouthRepublicanSWA</name>
        <Point>
            <coordinates>-102.255351,39.620417,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>FlaglerReservoirStateWildlifeArea</name>
        <Point>
            <coordinates>-102.994292,39.293958,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>LimonWetland</name>
        <Point>
            <coordinates>-103.677844,39.258691,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>SimlaPronghornLoop</name>
        <Point>
            <coordinates>-104.033625,39.160838,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>KinneyStateWildlifeArea</name>
        <Point>
            <coordinates>-103.43689,38.906778,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>FountainCreekRegionalPark</name>
        <Point>
            <coordinates>-104.726281,38.722361,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>ChicoBasin</name>
        <Point>
            <coordinates>-104.345359,38.651998,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>RockyFordStateWildlifeArea</name>
        <Point>
            <coordinates>-103.682054,38.065433,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>AdobeCreekReservoirStateWildlifeArea</name>
        <Point>
            <coordinates>-103.268029,38.256757,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>QueensStateWildlifeArea</name>
        <Point>
            <coordinates>-102.722507,38.334479,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>WillowCreekPark</name>
        <Point>
            <coordinates>-102.61408,38.077685,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>JohnMartinReservoirStateWildlifeArea</name>
        <Point>
            <coordinates>-102.988342,38.034914,0</coordinates>
        </Point>
    </Placemark>
</Document>
</kml>

So I got this to work when I took out the first name tag under the document tag. The real problem comes in when I try to use another file (which looks exactly the same to me) that I am creating by parsing an xml document with a Java program. I can load the file created in Notepad, but it gives a not-well-formed error when I try to load the file produced by the program. Something to do with my encoding? But I don't know how to change it.


Solution

  • I found the problem. It was mismatched tags. Makes you feel dumb, but seems to happen a lot in programming. Little things that are easy to miss. So make sure to check the tags well. Wasn't the encoding at all.