473,585 Members | 2,596 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Eleme ntTree as ET
import sys

#kml source is:
#<?xml version="1.0" encoding="UTF-8"?>
#<kml xmlns="http://earth.google.co m/kml/2.2">
# <Placemark>
# <name>Simple placemark</name>
# <description>At tached to the ground. Intelligently places itself
# at the height of the underlying terrain.</description>
# <Point>
# <coordinates>-122.08220354256 83,37.422289901 40251,0</
coordinates>
# </Point>
# </Placemark>
#</kml>
#select a file and open it in python
f_name=eg.fileo penbox("select kml file", "Select kml file")
f_kml=open(f_na me,'r')

#parse and create Elementtree and go to root
tree=ET.parse(f _kml)
kml=tree.getroo t()

#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 3021
Wi*********@gma il.com wrote:
I tried the tips I found in other posts but I still get 'none' back:

import easygui as eg
import xml.etree.Eleme ntTree as ET
import sys

#kml source is:
#<?xml version="1.0" encoding="UTF-8"?>
#<kml xmlns="http://earth.google.co m/kml/2.2">
# <Placemark>
# <name>Simple placemark</name>
# <description>At tached to the ground. Intelligently places itself
# at the height of the underlying terrain.</description>
# <Point>
# <coordinates>-122.08220354256 83,37.422289901 40251,0</
coordinates>
# </Point>
# </Placemark>
#</kml>
#select a file and open it in python
f_name=eg.fileo penbox("select kml file", "Select kml file")
f_kml=open(f_na me,'r')

#parse and create Elementtree and go to root
tree=ET.parse(f _kml)
kml=tree.getroo t()

#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.co m/kml/2.2'
coord=kml.fin d('{%s}Placemar k/{%s}Point/{%s}coordinates ' % \
(url, url, url)).text
>>print coord
'-122.08220354256 83,37.422289901 40251,0'

-Larry
Dec 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3725
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 contents of the file are as follows (i hope it will be rendered correctly): <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"...
1
3949
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> <SpecificInformation>
1
3057
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
1958
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 the XML document 2) The inherited code is somewhat 'brittle' in that some well-formed XML documents are not correctly processed by the code; the...
0
1106
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 elementtree import ElementInclude etree = ElementTree(file='xml_in.xml').getroot()
0
1266
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: AEDC To: python-list@python.org
0
1498
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 immediate child of root node i get back None. However if i comment the r = root.find('last')
11
3515
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 returns a elementtree, on which you can then apply xpath; 2) To parse a string (xml section), you can call XML or fromstring, but both return element...
1
294
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 = tree.getroot() ns = 'http://earth.google.com/kml/2.1' for folder in kml.findall("{%s}Folder/{%s}Folder/{%s}name" % (ns, ns, ns)): print folder.text
2
9784
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 tag, but I get None. data = """<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/ soap/envelope/"...
0
7835
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8195
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7947
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3831
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3856
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2340
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1444
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1171
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.