# How to parse a user-uploaded XML file in Python Dash?

**URL:** <https://community.plotly.com/t/how-to-parse-a-user-uploaded-xml-file-in-python-dash/38711>\
**Category:** Dash Python\
**Created:** [May 1, 2020, 3:41am UTC](https://community.plotly.com/t/how-to-parse-a-user-uploaded-xml-file-in-python-dash/38711 "2020-05-01T03:41:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![awa](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@awa](https://community.plotly.com/u/awa)\
**Post date:** [May 1, 2020, 3:41am UTC](https://community.plotly.com/t/how-to-parse-a-user-uploaded-xml-file-in-python-dash/38711/1 "2020-05-01T03:41:30Z")

</div>

New to Python and Dash, so sorry if this is a simple question.  
Looked online but could not find any answers.

I have a dcc.Upload object with an html.Button, where users can upload an XML file.  
Then, using a callback function, I would like to parse this file and return some simple data from the XML.  
In regular python I would do this with

```auto
tree = et.parse("file.xml")
root = tree.getroot()
...
for node in root:
    title = node.find("series_title").....

```

but this does not seem to work in Dash/HTML.  
Any idea how I would go about parsing files uploaded on Dash?  
I think it has something to with the ‘contents’ data created when uploading a file, but a bit lost.

Any help is appreciated, thank you!

---

<div class="post-metadata">

**Author:** ![awa](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@awa](https://community.plotly.com/u/awa)\
**Post date:** [May 1, 2020, 6:32pm UTC](https://community.plotly.com/t/how-to-parse-a-user-uploaded-xml-file-in-python-dash/38711/2 "2020-05-01T18:32:07Z")

</div>

Figured it out, and will leave this here in case others come across the same issue.

Looks like the ‘contents’ of the file is read in as ‘content\_string’ in base64.  
Decode it first, then set up a tree, which you can then get the nodes in each root from.

```auto
content_type, content_string = contents.split(',')
    # content_string is in base64, so decode it
    decoded = base64.b64decode(content_string)
    tree = et.ElementTree(et.fromstring(decoded))

    root = tree.getroot()
    for node in root:....

```
