I have below XML file:
<annotation>
<folder>JPEGImages</folder>
<filename>01FQ0YY92XRX5MDWGYC2RJ1CP4.jpeg</filename>
<path>D:\aVisionData\PVL Pilot Project\test\Annotation\JPEGImages\01FQ0YY92XRX5MDWGYC2RJ1CP4.jpeg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>601</width>
<height>844</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>smallObject</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>329</xmin>
<ymin>199</ymin>
<xmax>376</xmax>
<ymax>242</ymax>
</bndbox>
</object>
</annotation>
I want to remove <path> and also want to edit <source> </source> so it looks like below
<annotation>
<folder>JPEGImages</folder>
<filename>01FQ0YY92XRX5MDWGYC2RJ1CP4.jpeg</filename>
<source>
<database>objects</database>
<annotation>custom</annotation>
<image>custom</image>
</source>
<size>
<width>601</width>
<height>844</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>smallObject</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>329</xmin>
<ymin>199</ymin>
<xmax>376</xmax>
<ymax>242</ymax>
</bndbox>
</object>
</annotation>
To remove the <path>, I used below code:
import xml.etree.ElementTree as Et
file_path = os.path.join(inputAnnotationPath, annotation)
tr = Et.parse(file_path)
for element in tr.iter():
for subElement in element:
print(subElement)
if subElement.tag == "path":
se = subElement.get("path")
element.remove(subElement)
tr.write(sys.stdout)
It runs fine but not able to remove path. What changes I should do to remove the path and modify source.
pathis removed. I also see thatsourceis unmodified, but there's no logic/code for that, so I'm not surprised. I'm running 3.8.9.