I've used xml.etree.ElementTree and can parse through a L5XX with no problem but when I go to make a change to it, it breaks it.
</Rung> <Rung Number="0" Type="N"> <Text>" <![CDATA[[XIC(start);]]> </Text>
It changes the text but deletes the CDATA at the beginning of the line of code,
</Rung> <Rung Number="0" Type="N"> <Text>XIC(start);< /></Text>
Is it just the library formatting it incorrectly and I need to do it another way, or am I doing something wrong?
Code will be below.
import xml.etree.ElementTree as ET
xmlfile = (r"C:\Users\burgeB9\Desktop\L5X_Editor\MES Core
Build\_002_IGNITION_DATA_OVERALL_MACHINE.L5X")
tree = ET.parse(xmlfile)
RSLogix5000Content = tree.getroot()
#ET.dump(tree)
# Select Rung 0
Rung0 = RSLogix5000Content.find(".//Rung[@Number= '0']/Text")
print(Rung0.tag, Rung0.attrib, Rung0.text)
# Change Value in Rung 0
for Rung in RSLogix5000Content.findall(".//Rung[@Number= '0']/Text"):
Rung.text = "XIC(START);"
print(Rung.tag, Rung.attrib, Rung.text)
"""tree.write(xmlfile[:-4]+ "edit_XML")"""