# Read XML, CPython 3

**URL:** <https://forum.dynamobim.com/t/read-xml-cpython-3/76736>\
**Category:** Developers\
**Tags:** revit, dynamo, xml, civil3d\
**Created:** [May 20, 2022, 9:25am UTC](https://forum.dynamobim.com/t/read-xml-cpython-3/76736 "2022-05-20T09:25:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Drbohlav](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/drbohlav/32/113004_2.png) [@Drbohlav](https://forum.dynamobim.com/u/Drbohlav)\
**Post date:** [May 20, 2022, 9:25am UTC](https://forum.dynamobim.com/t/read-xml-cpython-3/76736/1 "2022-05-20T09:25:15Z")

</div>

Hi all,  
I would like to ask about the possibility of reading xml files in the new versions (2023) of Civil 3D and Revit, where CPython 3 is available. Does anyone have any experience they are willing to share?  
Regards  
Lukas

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [May 20, 2022, 9:53am UTC](https://forum.dynamobim.com/t/read-xml-cpython-3/76736/2 "2022-05-20T09:53:58Z")

</div>

to reading pure XML files, we can use **ElementTree XML API** (compatible both engine)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/7/2704caae765a4804e72b73a94b41294d217ed1ac.png)

```auto
import sys
import clr
import System
from System.IO import Path
import re
pyEngineName = sys.implementation.name 
if pyEngineName == "ironpython":
    pf_path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86)
    sys.path.append(pf_path + '\\IronPython 2.7\\Lib')
	
import xml.etree.ElementTree as ET
import xml.dom.minidom
import io
out = []
path_xml = IN[0]
try:
	with open(path_xml, 'r') as o:
		txt = o.read()
except:
	with io.open(path_xml, 'r', encoding='utf-8') as o:
		txt = o.read()
		
root = xml.etree.ElementTree.fromstring(txt)    
xmlBefore = ET.tostring(root)
mySearchTags = root.findall(".//Eclairage")
for myTag in mySearchTags:
    childs = myTag.getchildren()
    for node in childs:
       out.append([myTag.tag, node.tag])

OUT = out

```

---

<div class="post-metadata">

**Author:** ![mzjensen](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@mzjensen](https://forum.dynamobim.com/u/mzjensen)\
**Post date:** [May 20, 2022, 1:29pm UTC](https://forum.dynamobim.com/t/read-xml-cpython-3/76736/3 "2022-05-20T13:29:08Z")

</div>

Another example here:

> [@Subassembly composer enumeration - setting consistent keys to the inputs](https://forum.dynamobim.com/t/subassembly-composer-enumeration-setting-consistent-keys-to-the-inputs/59437/4):
>
> Hi @Soojung.Kim, After changing the .pkt to a .zip and unzipping it, you could try parsing the .emd file using the standard Python ElementTree module since it is formatted as an XML. Here’s an example: import xml.etree.ElementTree as ET file\_name = IN[0] attributes=[] xml = ET.parse(file\_name) root = xml.getroot() for group in root.iter('EnumItem'): attributes.append(group.attrib) OUT = attributes

---

<div class="post-metadata">

**Author:** ![Luffy11](https://avatars.discourse-cdn.com/v4/letter/l/919ad9/32.png) [@Luffy11](https://forum.dynamobim.com/u/Luffy11)\
**Post date:** [February 9, 2023, 4:00pm UTC](https://forum.dynamobim.com/t/read-xml-cpython-3/76736/4 "2023-02-09T16:00:02Z")

</div>

@c.poupin Hi, I try using your code but it returns me an empty list. Do you know why?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/d/fdbee60680e9b17f57fbbff68a0d797a16605a7f.png)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [February 9, 2023, 4:47pm UTC](https://forum.dynamobim.com/t/read-xml-cpython-3/76736/5 "2023-02-09T16:47:02Z")

</div>

Hi @Luffy11 ,  
probably you haven’t element node named “Eclairage” in your XML file, you need to adapt the code

the document is here

> **[xml.etree.ElementTree — The ElementTree XML API](https://docs.python.org/3/library/xml.etree.elementtree.html)**
>
> Source code: Lib/xml/etree/ElementTree.py The xml.etree.ElementTree module implements a simple and efficient API for parsing and creating XML data. Tutorial: This is a short tutorial for using xml....

---

<div class="post-metadata">

**Author:** ![Luffy11](https://avatars.discourse-cdn.com/v4/letter/l/919ad9/32.png) [@Luffy11](https://forum.dynamobim.com/u/Luffy11)\
**Post date:** [February 9, 2023, 4:50pm UTC](https://forum.dynamobim.com/t/read-xml-cpython-3/76736/6 "2023-02-09T16:50:11Z")

</div>

@c.poupin Thank you for replying me but I don’t know code. Is there any node in Dynamo with similar function?

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [February 9, 2023, 8:41pm UTC](https://forum.dynamobim.com/t/read-xml-cpython-3/76736/7 "2023-02-09T20:41:58Z")

</div>

Before there was the LunchBox package, but the development was stopped, now I don’t know

---

<div class="post-metadata">

**Author:** ![Luffy11](https://avatars.discourse-cdn.com/v4/letter/l/919ad9/32.png) [@Luffy11](https://forum.dynamobim.com/u/Luffy11)\
**Post date:** [February 10, 2023, 10:00am UTC](https://forum.dynamobim.com/t/read-xml-cpython-3/76736/8 "2023-02-10T10:00:12Z")

</div>

@c.poupin yeah, I’ve installed LunchBox package but can’t find the nodes relating to XML. Let me find another way. Thank you for your reply.
