Python minidom appendchild/insertBefore

Python minidom appendchild/insertBefore,python,xml,minidom,Python,Xml,Minidom,我正在使用Python和minidom在现有XML文件中插入数据。当我这样做时,我得到了正确的XML代码,但它看起来不像我想要的那样。 这是我的xml文件开头的一个示例 <?xml version="1.0" ?> <sim> <tool name="A"/> <calcSequence> <entry>FD_so</entry> <entry>FD_ped<

我正在使用Python和minidom在现有XML文件中插入数据。当我这样做时,我得到了正确的XML代码,但它看起来不像我想要的那样。 这是我的xml文件开头的一个示例

<?xml version="1.0" ?>
<sim>
    <tool name="A"/>
    <calcSequence>
        <entry>FD_so</entry>
        <entry>FD_ped</entry>
        <entry>FD_veh</entry>
    </calcSequence>
</sim>
结果是:

<calcSequence>
    <entry>FD_so</entry>
    <entry>FD_ped</entry>
    <entry>test</entry><entry>FD_veh</entry>
</calcSequence>

苏富民
FD_ped
testFD_veh
有没有办法在两个
之间插入缺少的换行符?
toprettyxml()不是一个解决方案,因为这只是xml的一小部分,我不想在文档的每一行后面插入空行

您是否尝试过在文本节点中插入换行符

# Put this after your existing code
newline = doc.createTextNode('\n')
calcSequence.insertBefore(newline, entrys[2])

谢谢,这使它变得更好,即使它不是整个解决方案。我必须添加正确数量的空格字符才能得到一个格式良好的xml。
# Put this after your existing code
newline = doc.createTextNode('\n')
calcSequence.insertBefore(newline, entrys[2])