parse xml string in a socket server

Sephiroth *TMM* alessandro at sephiroth.it
Mon Feb 24 18:54:37 EST 2003


yes, you're right.
I forgot the closing "?" in the previous message, but the xml i pass is correct also because when i parse the same string the
function work fine.
So, in the main socket server loop i receive clients' data in this way:

data = sockobj.recv(1024)
# then parse the string received
received = openXML(data)

and the openXML() function:

from xml.dom import minidom

def openXML(filename):
 print "parsing %s" % filename
 doc_node = minidom.parseString(filename)
 print doc_node
 return doc_node




the same string xml parsed apart works fine, but once i send the string with a socket client it raise me this error:

======

parsing <?xml version="1.0"?><ROOT><MESSAGE TYPE="getUserList" /></ROOT>
Traceback (most recent call last):
  File "C:\Python22\mytest\SocketServer\server.py", line 116, in ?
    received = openXML(data)
  File "C:\Python22\mytest\SocketServer\xmlparser.py", line 8, in openXML
    doc_node = minidom.parseString(filename)
  File "C:\Python22\Lib\site-packages\_xmlplus\dom\minidom.py", line 1605, in parseString
    return expatbuilder.parseString(string)
  File "C:\Python22\Lib\site-packages\_xmlplus\dom\expatbuilder.py", line 943, in parseStr
ing
    return builder.parseString(string)
  File "C:\Python22\Lib\site-packages\_xmlplus\dom\expatbuilder.py", line 189, in parseStr
ing
    parser.Parse(string, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 64

======================


--

Alessandro Crugnola [sephiroth]
Flash | PHP Developer
http://www.sephiroth.it

Team Macromedia Flash Volunteer
http://www.macromedia.com/go/team

Join the Flash-PHP mailing list
http://groups.yahoo.com/group/flash-php/join
________________________________
"Peter Hansen" <peter at engcorp.com> ha scritto nel messaggio news:3E5A95D8.6896005F at engcorp.com...
> Sephiroth *TMM* wrote:
> >
> > Hi to all,
> > i'm a newbie in python and i've this problem..
> >
> > i have no problem parsing an xml string with for example:
> >
> > xmlstring = "<?xml version=\"1.0\"><root><message>hi</message></root>"
> > from xml.dom import minidom
> > print "parsing %s" % xmlstring
> > doc = minidom.parseString(xmlstring)
> >
> > but if i put this in a function of a socket server which receive the xmlstring from a client ti gives me alway an error,
"invalid
> > token".
> > I don't know why, the print give me exactly the same string but the parseString failed anyway
>
> Please always cut and paste the output of your session including the precise
> error message and traceback, rather than paraphrasing.  Usually this is
> much more effective at helping us find the problem.
>
> In this case, I can see at least one problem: your XML processing
> instruction is incorrect, as it does not end with the proper closing
> sequence of "?>".  Try '<?xml version="1.0"?>' instead.  Not sure
> this will help, but it's at least the first problem.
>
> -Peter






More information about the Python-list mailing list