Bullet-proofing

This commit is contained in:
Sam Ruby 2006-11-04 13:03:54 -05:00
parent eb0f29963b
commit 13d9211b4d

View File

@ -25,7 +25,11 @@ illegal_xml_chars = re.compile("[\x01-\x08\x0B\x0C\x0E-\x1F]")
def createTextElement(parent, name, value): def createTextElement(parent, name, value):
""" utility function to create a child element with the specified text""" """ utility function to create a child element with the specified text"""
if not value: return if not value: return
if isinstance(value,str): value=value.decode('utf-8') if isinstance(value,str):
try:
value=value.decode('utf-8')
except:
value=value.decode('iso-8859-1')
xdoc = parent.ownerDocument xdoc = parent.ownerDocument
xelement = xdoc.createElement(name) xelement = xdoc.createElement(name)
xelement.appendChild(xdoc.createTextNode(value)) xelement.appendChild(xdoc.createTextNode(value))