Lxml --pretty_print-- write file problem

I am writing raw data to a python program for xml files, in my project we get the raw data line by line, then write it to an xml file, for example:

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

The first time I write to the xml file with pretty_print = True, I got what I want, but when the second time I read the file, I get the root of the element, --add-- new elements, and then save it with pretty_print = True, but I can’t get what I want, it’s just like:

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

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

+2
source share
1 answer
+3
source

All Articles