I wrote this code below. In my XML file I have nodes:
Assembly_1, Detail_1, Detail_2, Assembly_2, Detail_3
What I am trying to do is to get the name of the assembly for each detail (Detail_1 and 2 would be in Assembly_1, etc.)
I have a lot of details... more than 200. So this code (function) works good but it takes a lot of time because the XML file is loaded each time.
How can I make it run faster?
def CorrectAssembly(detail):
from xml.dom import minidom
xml_path = r"C:\Users\vblagoje\test_python_s2k\Load_Independent_Results\HSB53111-01-D_2008_v2-Final-Test-Cases_All_1.1.xml"
mydoc=minidom.parse(xml_path)
root = mydoc.getElementsByTagName("FEST2000")
assembly=""
for node in root:
for childNodes in node.childNodes:
if childNodes.nodeType == childNodes.TEXT_NODE: continue
if childNodes.nodeName == "ASSEMBLY":
assembly = childNodes.getAttribute("NAME")
if childNodes.nodeName == "DETAIL":
if detail == childNodes.getAttribute("NAME"):
break
return assembly