minidom and encoding problem

Ehab Teima ehab_teima at
Wed Jun 5 19:14:14 EDT 2002


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.

  File "D:\Python21\lib\xml\dom\", line 910, in parse
    return _doparse(pulldom.parse, args, kwargs)
  File "D:\Python21\lib\xml\dom\", line 902, in _doparse
    toktype, rootNode = events.getEvent()
  File "D:\Python21\lib\xml\dom\", line 234, in getEvent
  File "D:\Python21\lib\xml\sax\", line 92, in feed
  File "D:\Python21\lib\xml\sax\", 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.


More information about the Python-list mailing list