# How to create XML sub child element by Lunchbox

**URL:** <https://forum.dynamobim.com/t/how-to-create-xml-sub-child-element-by-lunchbox/27797>\
**Category:** Revit\
**Tags:** dynamo\
**Created:** [October 29, 2018, 4:44pm UTC](https://forum.dynamobim.com/t/how-to-create-xml-sub-child-element-by-lunchbox/27797 "2018-10-29T16:44:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liberrry](https://avatars.discourse-cdn.com/v4/letter/l/f9ae1b/32.png) [@Liberrry](https://forum.dynamobim.com/u/Liberrry)\
**Post date:** [October 29, 2018, 4:44pm UTC](https://forum.dynamobim.com/t/how-to-create-xml-sub-child-element-by-lunchbox/27797/1 "2018-10-29T16:44:14Z")

</div>

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

- 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,  
 ![Capture1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/2/f2f658328a666a289f73450c99253741706ab263.jpeg)

 ![Capture2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/6/d696503da8266d6807d14c1b04ff1fdcfb411fc9.jpeg)  
 ![Capture3](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/2/c27bd7c66454438020c54bbcfb6435f5275257e4.jpeg)  
 ![Capture4](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/9/89ce08522c20e161c3ee9eb0841d83685e4b42a6.jpeg)

---

<div class="post-metadata">

**Author:** ![andrew\_mehr](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@andrew\_mehr](https://forum.dynamobim.com/u/andrew_mehr)\
**Post date:** [May 7, 2019, 2:26am UTC](https://forum.dynamobim.com/t/how-to-create-xml-sub-child-element-by-lunchbox/27797/3 "2019-05-07T02:26:51Z")

</div>

I have a similar issue.  
@Liberrry , did you end up resolving (work around) this issue?

---

<div class="post-metadata">

**Author:** ![larissa.queirozJXN8V](https://avatars.discourse-cdn.com/v4/letter/l/50afbb/32.png) [@larissa.queirozJXN8V](https://forum.dynamobim.com/u/larissa.queirozJXN8V)\
**Post date:** [March 1, 2021, 7:01pm UTC](https://forum.dynamobim.com/t/how-to-create-xml-sub-child-element-by-lunchbox/27797/4 "2021-03-01T19:01:45Z")

</div>

Hey! Any updates about this issue? @Liberrry @andrew_mehr  
I’m with this problem.

---

<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:** [March 4, 2021, 4:54pm UTC](https://forum.dynamobim.com/t/how-to-create-xml-sub-child-element-by-lunchbox/27797/5 "2021-03-04T16:54:36Z")

</div>

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

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

```
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
```
