dict->XML->dict? Or, passing small hashes through text?

mackstann mack at incise.org
Fri Aug 15 00:25:36 EDT 2003


I don't have any in-depth experience with XML, but I think it is what I
want to use.  I'm basically passing little messages around, which are
basically just hashes, and up until now, I was using a dict that I
formatted to/parsed from a special syntax, but I keep running into
growing pains with that.  I'm using SocketServer, and each connection
sends one line of data, and then the connection is closed by the server.
I'm thinking that the ideal way that it would happen with XML in the mix
would be something like:

msg = {}
msg["foo"] = 1
msg["bar"] = "hello"
msg["abc"] = "text"

xmsg = xmlMessage(msg)

xmsg would now be a string such as:
'<?xml version="1.0"?><foo>1</foo><bar>hello</bar><abc>text</abc></xml>'

I could then send that over the wire, and on the other end, do something
like:

msg = xmlMessage2dict(xmsg)

And I'd have my dict back.  I don't think I'll be using values other
than strings and ints.  Dealing with variable types is something I'm
unsure of, e.g. making sure that I get back msg["foo"]==1, not
msg["foo"]=="1".

Everything I have found for handling XML seems to be centered around
parsing huge trees, and really complex data structures, etc.  I need no
DOM, XSLT, or any other fancy buzzwords associated with XML.  I
basically just need a simple way to turn hashes into text and back, and
I would really like for it to be language-independant.  XML seemed like
the obvious answer, but maybe it's not.  I'm very open to other
suggestions too. :)

-- 
m a c k s t a n n  mack @ incise.org  http://incise.org
Emerson's Law of Contrariness:
	Our chief want in life is somebody who shall make us do what we
can.  Having found them, we shall then hate them for it.





More information about the Python-list mailing list