Re: losing entities when parsing then texting

Andrew Clover <[email protected]>
Newsgroups gmane.comp.python.xml
Message-ID <[email protected]>
Greg Wilson <[email protected]> wrote:

> I realize I should include the Unicode characters directly in my files,
> but that's not possible in this case---I have to accommodate people who
> are using editors that only handle 7-bit ASCII.

Theoretically, .toxml('us-ascii') should generate usable output. 
Unfortunately minidom doesn't really do this properly and you'll get a 
UnicodeError.

As a workaround you could just take the UTF-8 encoded version and 
.encode('us-ascii', 'xmlcharrefreplace') on it... which is technically 
the wrong thing if nodeNames or CDATASections or whatever have non-ASCII 
characters in, but that probably doesn't matter to you.

ObStandardPlug: pxdom supports both proper charref-escaping (using 
DOM3LS DOMOutput.encoding) and keeping EntityReference nodes (using 
DOM3Core DOMConfiguration.setParameter('entities', True) or 
pxdom.parse(file, {'entities': True}).)

-- 
Andrew Clover
mailto:[email protected]
http://www.doxdesk.com/
_______________________________________________
XML-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/xml-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.