Hi guys,
Now I have been developing the dynamo script to generate XML file based on using Lunchbox node. The XML file that I want to create must be structured in the same way as this:
-
TenderDocument
-
Record
-
RecNo
-
Identification
-
ElementName
-
TradeSubject
-
LevelOfInformation
-
Quantity
-
Unit
-
PricePerUnit
-
Price
-
SpecificationRef
-
Properties
-
Properties
-
Record
-
TenderDocument
However, as I tried to create the sub child element :Properties, the sub child elements :Name, :Value and :Type did not come in the structure
Thus, I would like to know that how can I fix this issue?
Thanks with best regards,

I have a similar issue.
@Liberrry , did you end up resolving (work around) this issue?
Hey! Any updates about this issue? @Liberrry @andrew_mehr
I’m with this problem.
Hello
here is a Python solution to add xml (sub) child elements from an existing xml file
in the example below, we are looking for all the “properties” tags and adding child elements to them
import sys
import clr
import System
from System.IO import Path
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
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
path_xml = IN[0]
outxml = Path.GetDirectoryName(path_xml) + '\\'+ Path.GetFileNameWithoutExtension(path_xml) + "_v2.xml"
tree = ET.parse(path_xml)
root = tree.getroot()
xmlBefore = ET.tostring(root)
mySearchTags = root.findall(".//Properties")
for myTag in mySearchTags:
new1 = ET.SubElement(myTag, "Name")
new1.text = "MyProperty"
new2 = ET.SubElement(myTag, "Value")
new3 = ET.SubElement(myTag, "Type")
new3.text = "string"
#remove all blank character and set indents
xml_string = ''.join(ET.tostring(root).split())
dom = xml.dom.minidom.parseString(xml_string)
prettyXml = dom.toprettyxml()
with open(outxml, 'w') as f:
f.write(prettyXml)
OUT = xmlBefore, prettyXml
2 Likes