I'm trying to take data from a .csv file and create individual .xml files for each row. I've read the .csv into Pandas already. Where I'm struggling is trying to figure out how to make edits in .xml files.
I'm using this previous answer as a guide to try to learn this:
Applying the author's solution to my data would look something like this:
data = """<annotation>
<folder>VOC2007</folder>
<filename>abc.jpg</filename>
<object>
<name>blah</name>
<pose>unknown</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>0</xmin>
<ymin>0</ymin>
<xmax>0</xmax>
<ymax>0</ymax>
</bndbox>
</object>
</annotation>
"""
Then I do this:
tree = et.fromstring(data)
Where I'm stuck is the next part. The author edits their file with this line of code:
for data in tree.findall("data"):
name = data.attrib["name"]
value = data.find("value")
value.text = "[%s] %s" % (name, value.text)
I try to apply it to my own like this:
for data in tree.findall("data"):
filename = data.find("filename")
filename.text = "001.jpg"
But this doesn't seem to change anything when I print it out.
print(et.tostring(tree))
What am I doing wrong or what steps do I need to take to edit the name of the image from 'abc.jpg' to '001.jpg'?
Also trying to figure out how to change the values for the four items xmin, ymin, xmax, and ymax.