-1

I have PY 2.7 installed and when I try to write my XML to a file :

import xml.etree.ElementTree as xml
tree = xml.ElementTree(root)
with open(filename, 'w') as fh:
 tree.write(fh)

The above code works and the file is populated with the XML elements. Unfortunately its printing everything in one line. I have seen many options online printing in more human readible format. I tried a few with no success. Could someone propose what I can do in 2.7 try ?

Thanks, Newbie

1 Answers1

0

Fixed this one on my own. Had to import the indent() function from :

http://effbot.org/zone/element-lib.htm#prettyprint

with open(filename, 'w') as fh:
 indent(tree.getroot())
 tree.write(fh, encoding="ISO-8859-1")   

Thanks

Newbie