python: xml.etree.elementtree.ElemenTtree.write() 声明标签 [英] python: xml.etree.elementtree.ElemenTtree.write() declaration tag

查看:36
本文介绍了python: xml.etree.elementtree.ElemenTtree.write() 声明标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 xml.etree.elementtree.Element 创建了一个 XML 文档,并想使用 ElementTree.write() 函数打印它但是出来的声明标签是

I’ve created an XML document using xml.etree.elementtree.Element, and wanted to print it using the ElementTree.write() function but the declaration tag that comes out is

<?xml version='1.0' encoding='UTF-8'?>

虽然我需要用双引号.有没有办法改变它?

While I need to be in double quotes. is there a way to change that?

推荐答案

最终我使用了 tostring 函数并将 XML 附加到了正确的标签然后是 python file.write 函数.这很丑陋(而且我在文件的实际编码方面撒谎)但它有效.

Eventually I used the tostring function and appended the XML to the correct tag and then the python file.write function. It's ugly (and im lying about the actual encoding of the file) but it works.

这篇关于python: xml.etree.elementtree.ElemenTtree.write() 声明标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆