I'm trying to create a large XML file in memory that will be inserted into a Blob field in an ESRI feature class.
I attempted to use elementtree, but Python would eventually crash. I probably wasn't doing it the best way. An example of my code (not exact):
with update_cursor on feature class:
for row in update_cursor:
root = Element("root")
tree = ElementTree(root)
for id in id_list:
if row[0] in id:
equipment = Element("equipment")
root.append(equipment)
attrib1 = Element("attrib1")
equipment.append(attrib1)
attrib1.text = "myattrib1"
attrib2 = Element("attrib2")
equipment.append(attrib2)
attrib2.text = "myattrib2"
....and about 5 more of these appended to equipment
xml_data = ET.tostring(root)
insert xml_data into blob field
Example of the XML:
<root>
<equipment>
<attrib1>One</attrib1>
<attrib2>Two</attrib2>
<attrib3>Three</attrib3>
...
<attrib10>Ten</attrib10>
</equipment>
<equipment>
<attrib1>One</attrib1>
<attrib2>Two</attrib2>
<attrib3>Three</attrib3>
...
<attrib10>Ten</attrib10>
</equipment>
</root>
Now I realize this is probably a pretty amateur way of doing this, but I'm not sure of the best way to build this XML in memory.
For each row in the update_cursor, there could be multiple "equipment" elements added to the root, and each "equipment" element will have the exact same children elements but with different attributes.
I ran this and there were about 200 ids that matched a single row, so it had to create the equipment element and all the children of the equipment 200 times in memory.
So what is the best way to create XML in memory with Python using a standard library?
rowandid_list).