python - Formatting the output as XML with lxml -
my program read input file, makes lxml.etree file, example add node etree , want print on file. write on file use:
et.write('documents\write.xml', pretty_print=true)
and output have is:
<variable name="one" refid="two"><component type="three"><value>four</value></component></variable>
while i'd like:
<variable name="one" refid="two"> <component type="three"> <value>four</value> </component> </variable>
where mistaken? i've tried many solutions none seems work (beautifulsoup, tidy, parser...)
don't use standard parser. use custom parser remove_blank_text=true.
parser = etree.xmlparser(remove_blank_text=true) tree = etree.parse(self.output_file, parser=parser) // stuff tree here tree.write(your_output_file, pretty_print=true)
Comments
Post a Comment