By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,281 Members | 2,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

Elementtree find problem

P: n/a
I tried the tips I found in other posts but I still get 'none' back:

import easygui as eg
import xml.etree.ElementTree as ET
import sys

#kml source is:
#<?xml version="1.0" encoding="UTF-8"?>
#<kml xmlns="http://earth.google.com/kml/2.2">
# <Placemark>
# <name>Simple placemark</name>
# <description>Attached to the ground. Intelligently places itself
# at the height of the underlying terrain.</description>
# <Point>
# <coordinates>-122.0822035425683,37.42228990140251,0</
coordinates>
# </Point>
# </Placemark>
#</kml>
#select a file and open it in python
f_name=eg.fileopenbox("select kml file", "Select kml file")
f_kml=open(f_name,'r')

#parse and create Elementtree and go to root
tree=ET.parse(f_kml)
kml=tree.getroot()

#look for description
coord= kml.find('.//description')
print coord
_______________________

the result is 'None' ...

If I print out the kml with tostring I can see the entire file and to
me the XPath string also seems correct

any idea?
Dec 11 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Wi*********@gmail.com wrote:
I tried the tips I found in other posts but I still get 'none' back:

import easygui as eg
import xml.etree.ElementTree as ET
import sys

#kml source is:
#<?xml version="1.0" encoding="UTF-8"?>
#<kml xmlns="http://earth.google.com/kml/2.2">
# <Placemark>
# <name>Simple placemark</name>
# <description>Attached to the ground. Intelligently places itself
# at the height of the underlying terrain.</description>
# <Point>
# <coordinates>-122.0822035425683,37.42228990140251,0</
coordinates>
# </Point>
# </Placemark>
#</kml>
#select a file and open it in python
f_name=eg.fileopenbox("select kml file", "Select kml file")
f_kml=open(f_name,'r')

#parse and create Elementtree and go to root
tree=ET.parse(f_kml)
kml=tree.getroot()

#look for description
coord= kml.find('.//description')
print coord
_______________________

the result is 'None' ...

If I print out the kml with tostring I can see the entire file and to
me the XPath string also seems correct

any idea?
This works:
>>url='http://earth.google.com/kml/2.2'
coord=kml.find('{%s}Placemark/{%s}Point/{%s}coordinates' % \
(url, url, url)).text
>>print coord
'-122.0822035425683,37.42228990140251,0'

-Larry
Dec 11 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.