473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

xml.minidom and user defined entities

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.
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?

I've spend some time searching the docs/code/google but I haven't
found the answer to this question!

Thanks
--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Nov 9 '05 #1
2 5963
Nick Craig-Wood wrote:
I'm using xml.minidom to parse some of our XML files. Some of these
have entities like "&deg;" in which aren't understood by xml.minidom.
&deg; 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>

Nov 9 '05 #2
Fredrik Lundh <fr*****@pythonware.com> wrote:
Nick Craig-Wood wrote:
I'm using xml.minidom to parse some of our XML files. Some of these
have entities like "&deg;" in which aren't understood by xml.minidom.
&deg; is not a standard entity in XML (see below).


No probably not...
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).


The document doesn't define the entitys either internally or
externally. I don't fancy adding an inline definition either as there
are 100s of documents I need to process!
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).


I was kind of hoping I could poke my extra entities into some dict or
other in the guts of xml.minidom...

However the job demands quick and nasty rather than elegant so I'll go
for the regexp solution I think, as the list of entities is well
defined.

Thanks for your help

Nick
--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Nov 10 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Skip Montanaro | last post by:
I'd like to compare two xml.dom.minidom objects, but the naive attempt fails: >>> import xml.dom.minidom >>> d1 = xml.dom.minidom.parse("ES.xml") >>> d2 = xml.dom.minidom.parse("ES.xml") >>> d1...
6
by: Horst Gutmann | last post by:
Hi :-) I currently have quite a big problem with minidom and special chars (for example &uuml;) in HTML. Let's say I have following input file:...
4
by: Derek Basch | last post by:
Hello All, I ran into a problem while dynamically constructing XHTML documents using minidom. If you create a script tag such as: script_node_0 = self.doc.createElement("script")...
3
by: Kunle Odutola | last post by:
I have a database that tracks players for children's sports clubs. I have included representative DDL for this database at the end of this post. A single instance of this database supports...
13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
4
by: webdev | last post by:
lo all, some of the questions i'll ask below have most certainly been discussed already, i just hope someone's kind enough to answer them again to help me out.. so i started a python 2.3...
0
by: Gary | last post by:
Howdy I ran into a difference between Python on Windows XP and Linux Fedora 6. Writing a dom to xml with minidom works on Linux. It gives an error on XP if there is an empty namespace. The...
2
by: Dobedani | last post by:
Dear All, I guess I don't know where to look for the right information. I hope you guys can help me on the way. I want to retrieve a string from an XML-file. If Python were to have XPath...
2
by: =?iso-8859-1?q?KLEIN_St=E9phane?= | last post by:
Hi, I've a xml svg file and I would like to update it with Python. First, I would like to fetch one dom node with getElementByID. I've one issue about this method. This is my example : ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.