0

I added short_empty_elements=False to the write func of etree so that when I have an empty elements ,such as <\t>, it will write it in this format:

<root>
  <t></t>
</root>

My problem is that I need it to be in seperate lines, like this:

<root>
  <t>
  </t>
</root>

and I can't figure out how to do it.

.text='\n' or .text='' both don't work.

Is there any way to do it?

user3265447
  • 123
  • 2
  • 9

1 Answers1

0

While <t/> and <t></t> are equivalent,

<t/>

and

<t>
</t>

are not. The first form is an empty t element; the second, a t element that contains newline and space characters.

You will not find a serialization option to output the second form in place of the first. You will have to update the content of t to be as you wish prior to serialization, or, preferably, you will have to re-evaluate you motivation for such a suspect requirement in the first place.

See also

kjhughes
  • 106,133
  • 27
  • 181
  • 240