xml.dom.minidom - parseString - How to avoid ExpatError?

Gregory Piñero gregpinero at gmail.com
Tue Oct 25 14:59:35 EDT 2005


Hi guys,

I was hoping some XML expert could help me make this code work. Below is
sample code with sample XML similar to what I'm dealing with.

How can I make the weird characters in the XML not break the parser? I'll do
anything to make this work!

(Note: the   broke my parser yesterday but doesn't seem to in this
sample code) But really I'm looking for solutions that will handles lots
of unusual characters.

Much thanks,

Greg


<code>
from xml.dom.minidom import parseString
data="""
<blog>
<post>
This is sample problem text.   £500.00
</post>
</blog>
"""
myDOM=parseString(data)
</code>

<error>
Traceback (most recent call last):
File
"C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 307, in RunScript
debugger.run(codeObject, __main__.__dict__, start_stepping=0)
File "C:\Python23\Lib\site-packages\pythonwin\pywin\debugger\__init__.py",
line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
File "C:\Python23\Lib\site-packages\pythonwin\pywin\debugger\debugger.py",
line 631, in run
exec cmd in globals, locals
File "C:\Documents and Settings\Gregory\My Documents\Python\xml
help\xmlproc.py", line 9, in ?
myDOM=parseString(data)
File "C:\Python23\lib\xml\dom\minidom.py", line 1929, in parseString
return expatbuilder.parseString(string)
File "C:\Python23\lib\xml\dom\expatbuilder.py", line 940, in parseString
return builder.parseString(string)
File "C:\Python23\lib\xml\dom\expatbuilder.py", line 223, in parseString
parser.Parse(string, True)
ExpatError: undefined entity: line 4, column 29
</error>



--
Gregory Piñero
Chief Innovation Officer
Blended Technologies
(www.blendedtechnologies.com <http://www.blendedtechnologies.com>)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051025/b9dcb92e/attachment.html>


More information about the Python-list mailing list