Elementtree find problem

W

Willemsjunk

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

Larry Bates

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:
'-122.0822035425683,37.42228990140251,0'

-Larry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top