minidom and encoding problem
Ehab Teima
ehab_teima at hotmail.com
Wed Jun 5 19:14:14 EDT 2002
Hi,
I'm using Python 2.1. I wrote classes to create xml document from
scratch. The code worked fine until I hit an encoding problem. The
classes can read text and insert it as is to xml document using
creatTextNode. This text had characters > 127, and I got this error.
self._doc=xml.dom.minidom.parse(self._xml_filename)
File "D:\Python21\lib\xml\dom\minidom.py", line 910, in parse
return _doparse(pulldom.parse, args, kwargs)
File "D:\Python21\lib\xml\dom\minidom.py", line 902, in _doparse
toktype, rootNode = events.getEvent()
File "D:\Python21\lib\xml\dom\pulldom.py", line 234, in getEvent
self.parser.feed(buf)
File "D:\Python21\lib\xml\sax\expatreader.py", line 92, in feed
self._err_handler.fatalError(exc)
File "D:\Python21\lib\xml\sax\handler.py", line 38, in fatalError
raise exception
xml.sax._exceptions.SAXParseException: <unknown>:75:1: not well-formed
I know it's not possible to add an enconding attribute using writexml,
so the generated document only has <?xml version="1.0"?>. Is there any
way to get around this problem. I'd like to be able at least to parse
the document while reading using the proper encoding, such as,
encoding="ISO-8859-1". I'm only using minidom, any ideas how?
Another question:
Does any body know how to get the rootnode of a document? If I know
the root node, I can add the proper header and then write the root
node using writexml.
Thanks,
Ehab
More information about the Python-list
mailing list