Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Using the indent method

0 views
Skip to first unread message

dj

unread,
May 14, 2008, 3:25:45 PM5/14/08
to
Hello All,

I am using elementtree to write an XML document and I am having a hard
time adding the correct indentation.
I have tried using the indent method, but I can not figure out how to
use it. Any suggestions.

Mark Tolonen

unread,
May 14, 2008, 9:54:31 PM5/14/08
to

"dj" <d.a.ab...@gmail.com> wrote in message
news:ffbc75e3-612b-4195...@f63g2000hsf.googlegroups.com...

Using the version of indent() found on
http://effbot.org/zone/element-lib.htm:

>>> from xml.etree import ElementTree as ET
>>> x='<a><b /><c /><d>stuff</d><e><f /></e></a>'
>>> e=ET.fromstring(x)
>>> ET.dump(e)
<a><b /><c /><d>stuff</d><e><f /></e></a>
>>> indent(e)
>>> ET.dump(e)
<a>
<b />
<c />
<d>stuff</d>
<e>
<f />
</e>
</a>

-Mark

0 new messages