473,378 Members | 1,382 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 2993
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: alainpoint | last post by:
Hello, I use Elementtree to parse an elementary SVG file (in fact, it is one of the examples in the "SVG essentials" book). More precisely, it is the fig0201.svg file in the second chapter. The...
1
by: mirandacascade | last post by:
I do not understand how to use the find() method in ElementTree. The file 'sample.xml' is: <?xml version="1.0"?> <SampleRoot> <Header> <Product>FindMystery</Product> </Header>...
1
by: mirandacascade | last post by:
O/S: Windows 2K Vsn of Python: 2.4 Currently: 1) Folder structure: \workarea\ <- ElementTree files reside here \xml\ \dom\
2
by: mirandacascade | last post by:
Situation is this: 1) I have inherited some python code that accepts a string object, the contents of which is an XML document, and produces a data structure that represents some of the content of...
0
by: Mark E. Smith | last post by:
cElementTree cannot hold ElementTree instances. #from elementtree.ElementTree import ElementTree, dump # This works from cElementTree import ElementTree, dump # This does not from...
0
by: Mark | last post by:
-------- Original Message -------- Subject: Using cElementTree and elementtree.ElementInclude Date: Mon, 23 Oct 2006 09:40:24 -0500 From: Mark E. Smith <mark.e.smith@arnold.af.mil> Organization:...
0
by: sndive | last post by:
I have a weid problem. If i do this: import elementtree.ElementTree as ET .... tree = ET.parse("whatever") root = tree.getroot() r = root.find('last') print r return root where last is not an...
11
by: Peter Pei | last post by:
One bad design about elementtree is that it has different ways parsing a string and a file, even worse they return different objects: 1) When you parse a file, you can simply call parse, which...
1
by: Mike Slinn | last post by:
The following short Python program parses a KML file and displays the names of all Marks and Routes: from elementtree.ElementTree import ElementTree tree = ElementTree(file='test.kml') kml =...
2
by: Zvi | last post by:
Hi All, Can someone tell me why id the following not working? I have a soap response envelope, for test purpose it's just a string and I create ElementTree from it. Then I try to find Response...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.