468,766 Members | 1,523 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,766 developers. It's quick & easy.

xml with python <-> python deprecated - why?

Hi all

I need to pass data between a server program and a client program, both
written in Python.

My first thought was to use xml. The server builds up an xml string,
without using any xml tools. The client uses Sax to parse the string
received. Here is an example.

The server passes to the client the widgets required to set up a
screen. This is how it tells it to display a button -

self.gui += '<button label="%s" ref="%s" enabled="%s"
default="%s"/>' \
% (label,ref,enabled,default)

This is how the client deals with this -

MyButton(self.panel,attrs['label'],int(attrs['ref']),
int(attrs['enabled']),int(attrs['default']))

I have recently read that it is not a good idea to use xml unless it is
a specific requirement, so I changed it to passing a list of
dictionaries.

The server code now looks like this -

self.gui.append((GUI_BUTTON,{'label':label,'ref':r ef,
'enabled':enabled,'default':default}))

and the client code looks like this -

MyButton(self.panel,data['label'],data['ref'],
data['enabled'],data['default'])

Performance and readability are pretty much identical. The second
method results in a slightly longer string.

I am curious. Why is xml frowned upon? Is my new method ok, or is there
a better way?

Frank Millman

Dec 20 '05 #1
2 1488
Frank Millman wrote:

I am curious. Why is xml frowned upon? Is my new method ok, or is there
a better way?


Using XML gives you portability at the expense of increased code
manipulating the data structures.

Try creating a button with "<<<" as the label and you'll find why your xml
solution isn't ideal. For anything non-trivial you'll find it much better
to use one of the existing xml libraries to build your xml and then you'll
find why the non-xml solution looks simpler.

Generally speaking you make the decision to use xml or not based on a lot
of factors. Sometimes it is the best solution, other times using something
like a Python pickle might be better. Use whichever you are happy with
here.
Dec 20 '05 #2

Duncan Booth wrote:
Frank Millman wrote:

I am curious. Why is xml frowned upon? Is my new method ok, or is there
a better way?
Using XML gives you portability at the expense of increased code
manipulating the data structures.

Try creating a button with "<<<" as the label and you'll find why your xml
solution isn't ideal.


Good point.
For anything non-trivial you'll find it much better
to use one of the existing xml libraries to build your xml and then you'll
find why the non-xml solution looks simpler.

Another good point - things tend to get more complex as they evolve.
Generally speaking you make the decision to use xml or not based on a lot
of factors. Sometimes it is the best solution, other times using something
like a Python pickle might be better. Use whichever you are happy with
here.


My second method, using dictionaries instead of xml, seems equally
simple and equally fast, and it may save me some trouble in the future,
so I will run with it.

Thanks for the response

Frank

Dec 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jonny T | last post: by
7 posts views Thread by haoren | last post: by
3 posts views Thread by winderjj | last post: by
4 posts views Thread by matatu | last post: by
2 posts views Thread by Jasonkimberson | last post: by
4 posts views Thread by Armel Asselin | last post: by
3 posts views Thread by webmasterATflymagnetic.com | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.