473,387 Members | 1,534 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,387 software developers and data experts.

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 1655
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jonny T | last post by:
hi, i want to echo the string '<?php' in a php script like : echo "<?php"; but when i try nothing gets displayed ... if I use echo "<\?php";
7
by: haoren | last post by:
Can anybody help me with this problem: How can I echo a string that contain <? and <?php? For example, $str="test <? and <?php echo"; echo $str;
3
by: winderjj | last post by:
Hi All, I need everyones opinion. I am very new to XML but am temporarily putting all my efforts into using it. This is what I need to do. Write an xml parser (in C) that will parse a...
4
by: matatu | last post by:
Hi to all, I have a xml file, a substring like: &lt;a href=&quot;#&quot;&gt;text&lt;/a&gt; which after an xslt trasform is rendered as (using xsl:output method html): &lt;a...
5
by: tobbe | last post by:
Hi Im trying to load a XmlDataDocument with the following xml: <ROOT> <NAME> &LT; &AMP; &GT; " '</NAME> </ROOT> And i know I have a entity problem here, but i cant find any solution for...
2
by: Jasonkimberson | last post by:
I am doing a data pull of HTML from a database that will be put into a drop down menu currently after i pull and populate the information, it converts my < into &lt; whats the work around for...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
4
by: Armel Asselin | last post by:
Hello, I've been using XML for a while in a rather 'free' manner (i.e. as long as IE accept it it's OK), I read recently (again) the Xml standard 1.0 (3rd edition) and found this sentence: ...
4
by: spibou | last post by:
I saw it at http://www.faqs.org/rfcs/rfc1305.html Is it not the same as writing ``if (m)'' ?
3
by: webmasterATflymagnetic.com | last post by:
Folks, I'm struggling to put the question together, but I have this problem. I have written an HTML form that I can use for data entry. This uses PHP to write a SQL UPDATE command that gets...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.