I am trying to use Python 2.7 to parse a XML file, following the examples at
The part of interest in the file is:
<ns2:coordinates> 213142.650,146041.630 213142.820,146041.610 213143.340,146041.530 213143.860,146041.440 213144.880,146041.200 213145.380,146041.050 213145.880,146040.890 213146.370,146040.710 213146.860,146040.510 213147.340,146040.300 213147.810,146040.070 213148.280,146039.830 213148.730,146039.570 213149.180,146039.300 213149.340,146039.190 213149.780,146038.900 </ns2:coordinates>
And the following is my code:
from xml.etree import ElementTree as ET
from xml.etree.ElementTree import Element
from xml.etree.ElementTree import SubElement
namespaces = {'ns1': 'http://ift.tt/1yA0yeF', 'ns2': 'http://ift.tt/1HRGfTO'}
tree = ET.parse('C:\\Users\\James\\Desktop\\testFile.xml')
root = tree.getroot()
for section in root.findall('ns2:descriptiveTerm', namespaces):
coordinates = section.find('coordinates').text
print coordinates
There is a series of coordinates that following the namespace ns2, but none of them is shown on the screen.
May I know what is wrong with my code?
No comments:
Post a Comment