[英]remove <?xml version="1.0" ?> using xml.dom.minidom
I am generating XML files using xml.dom.minidom
.我正在使用xml.dom.minidom
生成 XML 文件。 Every time I generate a file on the very row there appears <?xml version="1.0" ?>
and the generated file looks like this:每次我在最一行生成一个文件时,都会出现<?xml version="1.0" ?>
并且生成的文件如下所示:
<?xml version="1.0" ?>
<Root>
data
</Root>
is not there anyway so have an output without and my output should look like无论如何都不在那里,所以没有输出,我的输出应该看起来像
<Root>
data
</Root>
If you are happy just to trim the first line from the file, use this code;如果您只想从文件中修剪第一行,请使用此代码;
f = open( 'file.txt', 'r' )
lines = f.readlines()
f.close()
f = open( 'file.txt'.'w' )
f.write( '\n'.join( lines[1:] ) )
f.close()
The best solution I found was to write out .childNodes[0]
, ie write out:我发现的最佳解决方案是写出.childNodes[0]
,即写出:
doc.childNodes[0].toprettyxml()
to the file, which will omit the xml version tag.到文件,这将省略 xml 版本标记。
这完成了 old_data 是要剥离的 xml 的工作
new_data = old_data[old_data.find("?>")+2:]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.