Read XML, CPython 3

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

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

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
4 Likes

Another example here:

2 Likes