Код: Выделить всё
foo<bar><Instruction><crow><grande>
foo<bar><Instruction><crow><grande>
Код: Выделить всё
from xml.etree import ElementTree as ET
def parse_xml(ele: ET.Element):
tag = ele.tag
if not isinstance(tag, str) and tag is not None:
return
t = ele.text
if t:
yield t
for e in ele:
parse_xml(e)
t = e.tail
if t:
yield t
def main():
fp = "path/to/xml"
tree = ET.parse(fp)
root = tree.getroot()
t_units = root.findall(".//{*}trans-unit")
for source, target in t_units:
for ele in parse_xml(source):
print(ele)
Код: Выделить всё
foo
Код: Выделить всё
def parse_xml(ele: ET.Element):
tag = ele.tag
if not isinstance(tag, str) and tag is not None:
return
t = ele.text
if t:
print(t)
for e in ele:
parse_xml(e)
t = e.tail
if t:
print(t)
Код: Выделить всё
foo
Подробнее здесь: https://stackoverflow.com/questions/790 ... is-present