Get all text from an XML document?

前端 未结 5 1185
闹比i
闹比i 2020-12-11 07:17

How can I get all the text content of an XML document, as a single string - like this Ruby/hpricot example but using Python.

I\'d like to replace XML tags with a sin

5条回答
  •  离开以前
    2020-12-11 07:28

    Using stdlib xml.etree

    import xml.etree.ElementTree as ET
    
    tree = ET.parse('sample.xml') 
    print(ET.tostring(tree.getroot(), encoding='utf-8', method='text'))
    

提交回复
热议问题