472,121 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

Elementtree find problem

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
1 2857
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.

Similar topics

4 posts views Thread by alainpoint | last post: by
1 post views Thread by mirandacascade | last post: by
1 post views Thread by mirandacascade | last post: by
2 posts views Thread by mirandacascade | last post: by
reply views Thread by Mark E. Smith | last post: by
1 post views Thread by Mike Slinn | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.