I am trying to get new line after the xml declaration due to a external software that rejects xml-file when not having the new line.
The XML-template (which works fine with the software):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Test_XML>
<DocumentProperties>
<Title>Setup</Title>
...
Parsing of template, editing and writing in new file with
from xml.dom import minidom
dat = minidom.parse('template.xml')
...
file = open("template_edited.xml", "w")
dat.writexml(file, indent='', addindent='', newl='', encoding='UTF-8', standalone='yes')
file.close()
The edited XML-file output is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Test_XML>
<DocumentProperties>
<Title>Setup</Title>
...
Edited version is rejected by software, as new line is missing.
I tried to solve issue by using toxml(); toprettyxml(); adding /n, adding empty newchild after declaration but nothing worked yet. Wanted to stay with xml methods and not starting to slice and join strings.
Do you have an idea to get the new line in the edited version or to prevent that the new line of the template gets lost in the process?
There is a similar question XmlDocument, preformatted xml: Add new line after XML declaration only, but I could not solve it with the answer.