Parsing XML with Python Script - Does not iterate through all elements

I’m trying to parse an XML file using the Python Script node in Dynamo, however it does not return values for all elements in Element Tree. I wonder why!! See below:

    import clr
    from Autodesk.DesignScript.Geometry import *

    import sys
    sys.path.append("C:\Program Files (x86)\IronPython 2.7\Lib")

    import xml.etree.ElementTree as ET
    dataEnteringNode= IN[0]
    tree = ET.parse(dataEnteringNode)
    root = tree.getroot()
    for clashresult in root.iter('clashresult'):
    # Assign your output to the OUT variable.
    OUT = name


Welcome to the community Arman!

Is it returning only the last data element of your file?
If so, it is because you reassign name in every iteration. Try to collect your names in a list and assign that list as output:

    # Container for OUT
    outlist = []
    for clashresult in root.iter('clashresult'):
        name = clashresult.get('name')
        # Append to container
    # Assign your output to the OUT variable.
    OUT = outlist

I also see you tried to upload an image. It was not uploaded because it´s inside the blockquote.

Kibar, Thanks a lot. I see now, it was only returning the last data.

1 Like