I'm using the following code to indent, as mentioned here:
parser = etree.XMLParser(remove_blank_text=True)
tree = etree.parse(filename, parser)
However, the original XML file is indented with 4 spaces and after using the code above it indents to 2 spaces. Any way to keep the 4 space indentation?
ADDED
I'm writing the tree like this:
xml = etree.parse("/path/to/the/xml/file")
with open("/file.xml", "wb") as f:
f.write(etree.tostring(xml, pretty_print=True, encoding='utf8'))
followed by the parse
and tree
variables above.