xml.minidom and user defined entities

Fredrik Lundh fredrik at pythonware.com
Wed Nov 9 14:51:57 EST 2005


Nick Craig-Wood wrote:

> I'm using xml.minidom to parse some of our XML files.  Some of these
> have entities like "°" in which aren't understood by xml.minidom.

° is not a standard entity in XML (see below).

> These give this error.
>
>  xml.parsers.expat.ExpatError: undefined entity: line 12, column 1
>
> Does anyone know how to add entities when using xml.minidom?

the document is supposed to contain the necessary entity declarations
as an inline DTD, or contain a reference to an external DTD.  (iirc, mini-
dom only supports inline DTDs, but that may have been fixed in recent
versions).

if you don't have a DTD, your document is broken (if so, and the set of
entities is known, you can use re.sub to fix replace unknown entities with
the corresponding characters before parsing.  let me know if you want
sample code).

</F> 






More information about the Python-list mailing list