473,406 Members | 2,954 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,406 software developers and data experts.

xml.minidom and threads

I have an application that uses xml to communicate between threads.
One of the threads in my app creates an xml message and sends it to a
second thread. This second thread parses the message and creates a new
xml message copying most part of the first message and sends it to a
third thread. The second thread was able to parse the message, while
the third thread is not able to parse the message that it received. I
am using minidom implementation of DOM to parse the messages. I am not
validating the messages.
So, I wrote this out to a file from the third thread and am able to
parse this from a stand alone non-threaded app.
I thought it might be an encoding issue, so I converted to utf-8 and
it still does not parse it.

The error message I get is here...
File "KQMLMessage.py", line 224, in CreateMessage
domDoc = xml.dom.minidom.parseString(message)
File "//usr/lib/python2.2/xml/dom/minidom.py", line 967, in
parseString
return _doparse(pulldom.parseString, args, kwargs)
File "//usr/lib/python2.2/xml/dom/minidom.py", line 954, in _doparse
toktype, rootNode = events.getEvent()
File "//usr/lib/python2.2/xml/dom/pulldom.py", line 255, in getEvent
self.parser.feed(buf)
File "//usr/lib/python2.2/xml/sax/expatreader.py", line 149, in feed
self._err_handler.fatalError(exc)
File "//usr/lib/python2.2/xml/sax/handler.py", line 38, in
fatalError
raise exception
SAXParseException: <unknown>:1:1: not well-formed (invalid token)

So, I came to suspect if xml.minidom module is thread-safe.
Any suggestions or comments are welcome.

thanks,
Sunil
Jul 18 '05 #1
3 2126
su********@hotmail.com (Sunil Movva) wrote in message news:<91**************************@posting.google. com>...
I have an application that uses xml to communicate between threads.
One of the threads in my app creates an xml message and sends it to a
second thread. This second thread parses the message and creates a new
xml message copying most part of the first message and sends it to a
third thread. The second thread was able to parse the message, while
the third thread is not able to parse the message that it received. I
am using minidom implementation of DOM to parse the messages. I am not
validating the messages.
So, I wrote this out to a file from the third thread and am able to
parse this from a stand alone non-threaded app.
I thought it might be an encoding issue, so I converted to utf-8 and
it still does not parse it.

The error message I get is here...
File "KQMLMessage.py", line 224, in CreateMessage
domDoc = xml.dom.minidom.parseString(message)
File "//usr/lib/python2.2/xml/dom/minidom.py", line 967, in
parseString
return _doparse(pulldom.parseString, args, kwargs)
File "//usr/lib/python2.2/xml/dom/minidom.py", line 954, in _doparse
toktype, rootNode = events.getEvent()
File "//usr/lib/python2.2/xml/dom/pulldom.py", line 255, in getEvent
self.parser.feed(buf)
File "//usr/lib/python2.2/xml/sax/expatreader.py", line 149, in feed
self._err_handler.fatalError(exc)
File "//usr/lib/python2.2/xml/sax/handler.py", line 38, in
fatalError
raise exception
SAXParseException: <unknown>:1:1: not well-formed (invalid token)

So, I came to suspect if xml.minidom module is thread-safe.
Any suggestions or comments are welcome.


I agree this sounds as if minidom isn't thread safe. If so the
fastest way to get this fixed is to come up with a simple test case
and post a bug to:

http://sourceforge.net/tracker/?grou...73&atid=106473

--Uche
Jul 18 '05 #2
Sunil Movva <su********@hotmail.com> wrote:
So, I came to suspect if xml.minidom module is thread-safe.


No it isn't, but I doubt this is your problem as you don't seem to be
trying to access the DOM Nodes from multiple threads, let alone
concurrently. (Is there any good reason why you need to serialise and
re-parse between each thread?)

A SAXParseException is generally what it says on the tin, caused by
faulty syntax in the XML document being parsed. It is conceivable that
minidom's serialisation code at the second-thread-output stage is
producing something wrong; we'd have to have a look at the string the
third thread is trying to parse to find out what.

--
Andrew Clover
mailto:an*@doxdesk.com
http://www.doxdesk.com/
Jul 18 '05 #3
an********@doxdesk.com (Andrew Clover) wrote in message news:<2c**************************@posting.google. com>...
Sunil Movva <su********@hotmail.com> wrote:
So, I came to suspect if xml.minidom module is thread-safe.


No it isn't, but I doubt this is your problem as you don't seem to be
trying to access the DOM Nodes from multiple threads, let alone
concurrently. (Is there any good reason why you need to serialise and
re-parse between each thread?)

A SAXParseException is generally what it says on the tin, caused by
faulty syntax in the XML document being parsed. It is conceivable that
minidom's serialisation code at the second-thread-output stage is
producing something wrong; we'd have to have a look at the string the
third thread is trying to parse to find out what.


I was able to fix this problem. It has nothing to do with
thread-safety. The function xml.dom.minidom.parseString() throws
invalid token exception on trying to parse unicode strings. I forced
my app to use regular strings instead.

Thanks for the response.
-Sunil
Jul 18 '05 #4

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

Similar topics

0
by: xtian | last post by:
Hi - I'm doing some data conversion with minidom (turning a csv file into a specific xml format), and I've hit a couple of small problems. 1: The output format has a header with some xml that...
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...
5
by: Mike McGavin | last post by:
Hi everyone. I've been trying for several hours now to get minidom to parse namespaces properly from my stream of XML, so that I can use DOM methods such as getElementsByTagNameNS(). For some...
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: 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...
18
by: sim.sim | last post by:
Hi all. i'm faced to trouble using minidom: #i have a string (xml) within CDATA section, and the section includes "\r\n": iInStr = '<?xml version="1.0"?>\n<Data><!]></Data>\n' #After i...
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...
3
by: aine_canby | last post by:
Hi, I'm working with a number of scripts which were written years ago for my company for Python 2.2, and I'd like to update for Python 2.5. I have written a script to add # -*- coding: cp1252...
2
by: ashmir.d | last post by:
Hi, I am trying to parse an xml file using the minidom parser. <code> from xml.dom import minidom xmlfilename = "sample.xml" xmldoc = minidom.parse(xmlfilename) </code> The parser is...
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.