newlines and sax.saxutils.quoteattr

Edward K. Ream edreamleo at
Tue Sep 19 17:10:21 CEST 2006

Hello all,

I recently ran across a situation in which sax.saxutils.quoteattr did not 
work as I expected.  I am writing Leo outlines as opml files
which forces me to write python code in xml attributes rather than xml 
elements (as is done in .leo files).

The problem is that the sax parser I am using ignores newlines in 
attributes.  After reading the thread at:

I was able to work around the problem by converting newlines to '
This makes the opml file as readable as possible (since the attributes 
contains newlines in addition to the character reference 
  In addition, 
the sax parser seems happy.

My questions:

- Does anyone know whether this is guaranteed to be a general solution? That 
is, are sax parsers *obliged* to ignore newlines in attributes?

- If sax parsers are indeed obliged to ignore newlines in attributes, would 
it be a good idea to (optionally?) have sax.saxutils.quoteattr perform the 
substitution of newlines to '
\n' ?


Edward K. Ream   email:  edreamleo at

More information about the Python-list mailing list