[XML-SIG] Whitespace handling in XMLWriter

Radestock, Guenter guenter.radestock@sap.com
Sun, 25 Feb 2001 20:23:13 +0100

> -----Original Message-----
> From: Radestock, Guenter 
> Sent: Sonntag, 25. Februar 2001 19:26
> To: 'XML-SIG@python.org'
> Subject: [XML-SIG] Whitespace handling in XMLWriter
> I am using xml.sax.writer to produce nicely indentex XML 
> output from Python.
> The xmlwriter is pretty good at indentation and formatting, 
> but for some
> tags, I would like to have whitespace preserved.  I did not see a way
> to tell this via the doctype info.  

diving in a little deeper I have found that when I call

   self.docinfo.add_attribute_defn(tagname, 'xml:space', None, None,

just before opening the tag tagname, it will preserve the whitespace the
way I want it to.  Now two little problems remain:

1. the tag itself will not be indented.  The place the tag is put
into the output should not have anything to do with how its content
is formatted?

2. the pretty printer does not behave properly when formatting empty
tags (a linefeed is missing after the empty tag).

You can see both in the output fragment below:

<LAISO/>            </Index>

- Guenter