<?xml version="1.0"?><kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<name>Test KML</name>
<description><![CDATA[<p>This is a test version.</p>]]></description>
<Style id="spstyle7">
<IconStyle>
<color>ff4DF6D8</color>
<Icon><href>http://maps.google.com/mapfiles/kml/paddle/wht-blank.png</href></Icon>
</IconStyle>
<LineStyle>
<color>ff4DF6D8</color>
<width>4</width>
</LineStyle>
</Style>
<Folder>
<name>Track1</name>
<visibility>0</visibility>
<name>Test1</name>
<description><![CDATA[test1]]></description>
<Placemark>
<name>test1</name>
<description><![CDATA[test1]]></description>
<MultiGeometry>
<LineString>
<tessellate>true</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
11.000,4.000 11.000,3.000
</coordinates>
</LineString>
<LineString>
<tessellate>true</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
11.000,4.000 12.000,4.000
</coordinates>
</LineString>
<LineString>
<tessellate>true</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
12.000,5.000 12.000,4.000
</coordinates>
</LineString>
</MultiGeometry>
</Placemark>
</Folder>
<Style id="spstyle7">
<IconStyle>
<color>ff4DF6D8</color>
<Icon><href>http://maps.google.com/mapfiles/kml/paddle/wht-blank.png</href></Icon>
</IconStyle>
<LineStyle>
<color>ff4DF6D8</color>
<width>4</width>
</LineStyle>
</Style>
<Folder>
<name>Track2</name>
<visibility>0</visibility>
<name>Test2</name>
<description><![CDATA[test2]]></description>
<Placemark>
<name>test2</name>
<description><![CDATA[test2]]></description>
<MultiGeometry>
<LineString>
<tessellate>true</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
8.000,8.000 8.000,7.000
</coordinates>
</LineString>
<LineString>
<tessellate>true</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
8.000,7.000 11.000,6.000
</coordinates>
</LineString>
<LineString>
<tessellate>true</tessellate>
<altitudeMode>clampToGround</altitudeMode>
<coordinates>
9.000,1.000 10.000,1.000
</coordinates>
</LineString>
</MultiGeometry>
</Placemark>
</Folder>
</Document>
</kml>
协调
标记,可以放入列表或列表列表(每个文件夹一个)。
首先,我编写了以下代码:
import xml.etree.ElementTree as ET
tree = ET.parse("test.kml")
root = tree.getroot()
results = root.findall('Folder')
textnumbers = [r.find('Placemark/LineString/coordinates').text for r in results]
print textnumbers
文件夹
名称,代码如下:
for folder in root.findall('Folder'):
name = folder.find('name')
print name
我还得到一个空字符串。为什么解析器没有找到
标签有什么提示吗?
提前感谢您提供的任何帮助。