---
title: "Send xml file using python"  
description: "Send xml file using python"  
author: "Anonymous User"  
published: 2014-11-05  
updated: 2014-11-06  
canonical: https://www.mindstick.com/forum/2523/send-xml-file-using-python  
category: "xml"  
tags: ["python-3.4"]  
reading_time: 2 minutes  

---

# Send xml file using python

[Reading](https://www.mindstick.com/articles/126273/books-commonly-found-on-college-reading-lists) the [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) from overpass-[API](https://www.mindstick.com/articles/12641/instagram-api-upgraded-to-facebook-graph), I have no [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) getting the [basic](https://www.mindstick.com/forum/161830/what-are-the-security-risks-of-using-basic-authentication) fields. From the below example, the lat and lon are easily read. What I cannot manage is the read the various [tags](https://www.mindstick.com/interview/33868/difference-between-html-elements-and-tags) with K=xxxx, v=yyyyy ; I need to read the one with k="[name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide)" so as to build a list of city name, lat, lon.

The data included in this [document](https://www.mindstick.com/articles/328642/what-to-consider-while-choosing-a-software-documentation-tool) is from www.openstreetmap.org. The data is made available under ODbL.

```
<node id="31024030" lat="51.0763933" lon="4.7224848">  <tag k="is_in" v="Antwerpen, Belgium, Europe"/>  <tag k="is_in:continent" v="Europe"/>  <tag k="is_in:country" v="Belgium"/>  <tag k="is_in:province" v="Antwerp"/>  <tag k="name" v="Heist-op-den-Berg"/>  <tag k="openGeoDB:auto_update" v="population"/>  <tag k="openGeoDB:is_in" v="Heist-op-den-Berg,Heist-op-den-Berg,Mechelen,Mechelen,Antwerpen,Antwerpen,Vlaanderen,Vlaanderen,Belgique,Belgique,Europe"/>
```

[Code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) that I have as yet:

```
import xml.etree.cElementTree as ETtree = ET.parse('target.osm')root = tree.getroot()allnodes=root.findall('node')for node in allnodes:   lat=node.get('lat')   lon=node.get('lon') cityname='' # set default in case proper tag not found for tag in node.getiterator():     print tag.attrib     # add code here to get the cityname  print lat,lon,cityname
```

## Replies

### Reply by Pravesh Singh

You need to iterate over all children of each node and search for an element with a k="name" attribute:

```
for tag in node.findall('tag'):
    if tag.attrib['k'] == 'name':
        cityname = tag.attrib['v']
```

Or by using your get() approach:

```
for tag in node.findall('tag'):
    if tag.get('k') == 'name':
        cityname = tag.get('v')
```


---

Original Source: https://www.mindstick.com/forum/2523/send-xml-file-using-python

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
