[XML-SIG] Newbie : Identifying characters that will choke XML parser

Ian Sparks Ian.Sparks@etrials.com
Mon, 5 May 2003 16:45:48 -0400


I build an XML document from data pulled from a database. Sometimes the =
database contains "bad" characters, how can I filter out the bad and =
properly encode the good?

Here's my example program...I'm sure I'm missing something fundamental.=20

from xml.dom.minidom import parseString

bad_string =3D chr(133) + chr(6) + chr(180)

doc1 =3D parseString('<test/>')
docNode =3D doc1.childNodes[0]
docNode.setAttributeNS(None,'a',unicode(bad_string,'iso-8859-1'))
source =3D doc1.toxml('iso-8859-1')   #result is badly formed xml