Answers for "xml to txt python"

3

python string to xml

import xml.etree.ElementTree as ET

root = ET.fromstring(country_data_as_string)
Posted by: Guest on June-18-2020
0

how to write pretty xml to a file python

# Use lxml as the core library for xml manipulation. 
from lxml import etree

xml_object = etree.tostring(root,
                            pretty_print=True,
                            xml_declaration=True,
                            encoding='UTF-8')

with open("xmlfile.xml", "wb") as writter: # wb - write bytes mode
    writter.write(xml_object)`
Posted by: Guest on May-28-2021

Python Answers by Framework

Browse Popular Code Answers by Language