Search
 
SCRIPT & CODE EXAMPLE
 

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)`
Comment

PREVIOUS NEXT
Code Example
Python :: when to use python sets 
Python :: arcpy line density 
Python :: Spatial Reference arcpy 
Python :: for 2d data compute standard deviation at each x 
Python :: HttpResponse Object Error in view.py 
Python :: same line print python 
Python :: Pipeline_parameters 
Python :: how to stop a while loop in opencv 
Python :: pygame download for python 3.10 
Python :: select all Textinput kivy on selection 
Python :: groupby sum and mean 2 columns 
Python :: useful functions in python 
Python :: how to select specific column with Dimensionality Reduction pyspark 
Python :: 2d arrary.push in python 
Python :: limiting user input to under 100 characters python 
Python :: current python 
Python :: What is shadows built in name? 
Python :: converting 1d array into upper triangular 
Python :: python class private variables 
Python :: python scale function 
Python :: python project pick text color according to background 
Python :: pandas read csv skip until expression found 
Python :: treat NaN as a category 
Python :: can only concatenate str (not "numpy.uint8") to str 
Python :: python consecutive numbers difference between 
Python :: how to convert small letters to capital letters in python 
Python :: fibonacci formula python 
Python :: duplicate characters in a string python 
Python :: axes turn of axis matplotlb 
Python :: Form rendering options in django 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =