I have an XML document called sync_list.xml structured like this:
root = ET.Element("root")
synced = ET.SubElement(root, "synced")
synced.set("name", "Already Synced")
sfile = ET.SubElement(synced, "sfile")
sfile.set("name", "Filename")
sfile.text = "base"
tree = ET.ElementTree(root)
tree.write("sync_list.xml")
so that I end up with:
<root><synced name="Already Synced"><sfile name="Filename">base</sfile></synced></root>
and I’m multiple files within a directory. I would like to “append” those file names as a new sfile entry each time a file is opened. So I would end up with something like this:
<root><synced name="Already Synced"><sfile name="Filename">base</sfile><sfile name="Filename">File1.blah</sfile><sfile name="Filename">File2.blah</sfile><sfile name="Filename">File3.blah</sfile></synced></root>
How would I achieve this? Thank you so much for your help.
You almost there. You just need to read the file back and find the
<synced>element in it: