Код: Выделить всё
Some bad[/b] text [i]that[/i] I [u]do [i]not[/i][/u] want to keep.
Код: Выделить всё
from __future__ import print_function
import xml.etree.ElementTree as ET
tree = ET.parse('a.xml')
root = tree.getroot()
parent_map = {c:p for p in root.iter() for c in p}
for item in root.findall('.//b'):
parent_map[item].remove(item)
for item in root.findall('.//u'):
parent_map[item].remove(item)
print(''.join(root.itertext()).strip())
Код: Выделить всё
Some that I
Код: Выделить всё
Some text that I want to keep.
Подробнее здесь: https://stackoverflow.com/questions/229 ... t-after-it
Мобильная версия