lxml --pretty_print--写入文件问题

发布于 2024-10-06 19:55:15 字数 417 浏览 0 评论 0原文

我正在将原始数据写入xml文件python程序,在我的设计中,我们逐行获取原始数据, 然后将其写入 xml 文件,例如:

`<root>\n
  <a> value </a>\n
  <b> value </b>\n
</root>

第一次使用 Pretty_print=True 写入 xml 文件时,我得到了我想要的,但是当第二次 当我读取文件时,获取元素根,--add--新元素,然后使用 Pretty_print=True 将其保存回来,但我无法得到我想要的,它就像:

...\n
<c> value </c></root>

` lxml 有什么问题吗?还是我的错?

I am write a raw data to xml file python program, in my design,we get the raw data line by line,
then write it into xml file like:

`<root>\n
  <a> value </a>\n
  <b> value </b>\n
</root>

The first time i write into xml file with pretty_print=True, i got what i want, but when the second
time i read the file, get the element root, --add-- new elemnts then save it back with pretty_print=True, but i can not get what i want,it just like:

...\n
<c> value </c></root>

`
what's wrong with lxml? Or my fault?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠我空喜 2024-10-13 19:55:15

您可能会在 lxml 常见问题解答中找到答案: 为什么 Pretty_print 选项不重新格式化我的 XML 输出?

You might find the answer in the lxml faq: Why doesn't the pretty_print option reformat my XML output?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文