KML文档有效,但是当以编程方式编写时,编码是错误的?

时间:2012-12-03 17:34:13

标签: xml kml google-earth

<?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>

所以当我拿出文档标签下的第一个名称标签时,我得到了这个。当我尝试通过使用Java程序解析xml文档来创建我正在创建的另一个文件(看起来与我完全相同)时,真正的问题就出现了。我可以加载在记事本中创建的文件,但是当我尝试加载程序生成的文件时,它会给出一个格式错误的错误。与我的编码有关?但我不知道如何改变它。

2 个答案:

答案 0 :(得分:2)

将文件重命名为xml,并在Internet浏览器或任何其他Xml编辑器中打开。然后,您会看到是否存在不匹配的打开关闭标记的问题。

我检查了你的文件,它确实有效!

黄色标记,美国地标。一切都很好。 检查Google地球安装。

请注意:要在Google地图上显示km lfile,该文件必须位于公共可访问的网址上。 Google地球没有此限制

答案 1 :(得分:0)

我发现了问题。这是不匹配的标签。让你感到愚蠢,但似乎在编程中发生了很多。容易错过的小事。因此,请务必仔细检查标签。根本不是编码。