0

Bunch of XML files with same no. of lines. Need to remove particular lines from all of these similar looking XML files.

import xml.etree.ElementTree as ET
file = ET.parse('a.xml')
root = file.getroot()
for elem in root.findall('.//Begin/Inbetween'):
    delete_rows = elem.rows(5, 6 , 7, 8)
            elem.remove(delete_rows)
file.write('b.xml')
Progman
  • 16,827
  • 6
  • 33
  • 48
daredevil
  • 1
  • 1
  • Please share a example xml and the expected result, what you like to create. Makes it easier to understand what you problem is. You have to search the parent tag to remove the child tag, like `parent.remove(child)`. – Hermann12 Aug 26 '23 at 20:28
  • `xml.etree.ElementTree` doesn’t know the row. You have to specify the list index and then use remove(). Find the description [here](https://docs.python.org/3/library/xml.etree.elementtree.html). – Paul-ET Aug 28 '23 at 17:29

0 Answers0