I'm using BeautifulSoup to build xml files.
It seems like my two are options are 1) no formatting i.e.
<root><level1><level2><field1>val1</field1><field2>val2</field2><field3>val3</field3></level2></level1></root>
or 2) with prettify i.e.
<root>
<level1>
<level2>
<field1>
val1
</field1>
<field2>
val2
</field2>
<field3>
val3
</field3>
</level2>
</level1>
</root>
But i would really prefer it to look like this:
<root>
<level1>
<level2>
<field1>val1</field1>
<field2>val2</field2>
<field3>val3</field3>
</level2>
</level1>
</root>
I realise i could hack bs4 to achieve this result but i would like to hear if any options exist.
I'm less bothered about the 4-space indent (although that would be nice) and more bothered about the newline after any closing tags or between two opening tags. I'm also intrigued is there a name for this way of formatting as it seems the most sensible way to me.
html.parser
is ok, then see my answer. – Chirp