473,574 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(me ssage)
File "//usr/lib/python2.2/xml/dom/minidom.py", line 967, in
parseString
return _doparse(pulldo m.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.fee d(buf)
File "//usr/lib/python2.2/xml/sax/expatreader.py" , line 149, in feed
self._err_handl er.fatalError(e xc)
File "//usr/lib/python2.2/xml/sax/handler.py", line 38, in
fatalError
raise exception
SAXParseExcepti on: <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 2159
su********@hotm ail.com (Sunil Movva) wrote in message news:<91******* *************** ****@posting.go ogle.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(me ssage)
File "//usr/lib/python2.2/xml/dom/minidom.py", line 967, in
parseString
return _doparse(pulldo m.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.fee d(buf)
File "//usr/lib/python2.2/xml/sax/expatreader.py" , line 149, in feed
self._err_handl er.fatalError(e xc)
File "//usr/lib/python2.2/xml/sax/handler.py", line 38, in
fatalError
raise exception
SAXParseExcepti on: <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********@hot mail.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 SAXParseExcepti on 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*@doxd esk.com
http://www.doxdesk.com/
Jul 18 '05 #3
an********@doxd esk.com (Andrew Clover) wrote in message news:<2c******* *************** ****@posting.go ogle.com>...
Sunil Movva <su********@hot mail.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 SAXParseExcepti on 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
7488
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 looks something like this: <item xmlns="" xmlns:thing="http://www.blah.com"> <thing:child name="smith"/> </item>
5
4814
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 == d2 False My goal is to decide whether or not I need to prompt the user to save config information at the end of a program run by generating a...
5
6361
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 reason, though, it just doesn't seem to want to split the prefixes from the rest of the tags when parsing. The minidom documentation at...
6
3971
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: -------------------------------------------------- <?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>
4
6051
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 script that grabs some web pages from the web, regex parse the data and stores it localy to xml file for further use.. at first i had no problem using...
18
758
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 create DOM-object, i get the value of "Data" without "\r\n"
0
1509
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 problem was handled in CVS a while ago. http://mail.python.org/pipermail/xml-sig/2003-October/009904.html
3
1994
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 -*- to the beginning of all my scripts, and that has fixed the encoding issues. Another issue was the use of - from _xmlplus.dom import minidom
2
12558
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 failing on this line:
0
7801
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8044
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8229
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7808
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5299
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3739
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3749
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.