I have a problem related to a Google Earth exported KML, as it doesn't seem to work well with Element Tree. I don't have a clue where the problem might lie, so I will explain how I do everything.
Here is the relevant code:
kmlFile = open( filePath, 'r' ).read( -1 ) # read the whole file as text kmlFile = kmlFile.replace( 'gx:', 'gx' ) # we need this as otherwise the Element Tree parser # will give an error kmlData = ET.fromstring( kmlFile ) document = kmlData.find( 'Document' )
With this code, ET (Element Tree object) creates an Element object accessible via variable kmlData. It points to the root element ('kml' tag). However, when I run a search for the sub-element 'Document', it returns None. Although the 'Document' tag is present in the KML file!
Are there any other discrepancies between KMLs and XMLs apart from the 'gx: smth' tags? I have searched through the KML files I am dealing with and found nothing suspicious. Here is a simplified structure of an KML file the program is supposed to deal with:
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.2"> <Document> <name>UK.kmz</name> <Style id="sh_blu-blank"> <IconStyle> <scale>1.3</scale> <Icon> <href>http://maps.google.com/mapfiles/kml/paddle/blu-blank.png</href> </Icon> <hotSpot x="32" y="1" xunits="pixels" yunits="pixels"/> </IconStyle> <ListStyle> <ItemIcon> <href>http://maps.google.com/mapfiles/kml/paddle/blu-blank-lv.png</href> </ItemIcon> </ListStyle> </Style> [other style tags...] <Folder> <name>UK</name> <Placemark> <name>1262 Crossness Pumping Station</name> <LookAt> <longitude>0.1329926667038817</longitude> <latitude>51.50303535104574</latitude> <altitude>0</altitude> <range>4246.539753518848</range> <tilt>0</tilt> <heading>-4.295161152207489</heading> <altitudeMode>relativeToGround</altitudeMode> <gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode> </LookAt> <styleUrl>#msn_blu-blank15000</styleUrl> <Point> <coordinates>0.1389579668507301,51.50888923518947,0</coordinates> </Point> </Placemark> [other placemark tags...] </Folder> </Document> </kml>
Do you have an idea why I can't access any sub-elements of 'kml'? By the way, Python version is 2.7.
Source: http://stackoverflow.com/questions/17811880/element-tree-doesnt-load-a-google-earth-exported-kml
la riots rachel maddow gia utah jazz lawrence of arabia denver nuggets new jersey devils
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.