Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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)`
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #write #pretty #xml #file #python
ADD COMMENT
Topic
Name
5+8 =