2

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.

Community
  • 1
  • 1
bulkmoustache
  • 1,875
  • 3
  • 20
  • 24
  • Maybe I jumped the gun on this one ... How are you actually _writing_ the lxml tree? All you're showing here is how you _read_ the tree. – mgilson Apr 11 '14 at 17:15

0 Answers0