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,enab led,default)
This is how the client deals with this -
MyButton(self.p anel,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,'r ef':ref,
'enabled':enabl ed,'default':de fault}))
and the client code looks like this -
MyButton(self.p anel,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 2 1680
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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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";
|
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;
|
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 fairly complicated XML
file that is full of technical data(most scalar values). Then I need
to store all the info in a C structure. Could some people give me
their opinion. Which is better suited for this, Expat or LT xml?
|
by: matatu |
last post by:
Hi to all,
I have a xml file, a substring like:
<a href="#">text</a>
which after an xslt trasform is rendered as (using xsl:output method html):
<a href="#">text</a>
|
by: tobbe |
last post by:
Hi
Im trying to load a XmlDataDocument with the following xml:
<ROOT>
<NAME> < & > " '</NAME>
</ROOT>
And i know I have a entity problem here, but i cant find any solution for
it. The problem is that i recive this from external source and cant
| |
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 <
whats the work around for this?
HTML code
|
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, the XML specification seems a little ambiguous on this, so
I defer to the XML authorities. Refer to sections 2.4 and 2.7 (it all
hinges on if CDATA attribute values are part of markup or not.)
Thanks.
|
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:
Well-formedness constraint: No < in Attribute Values
The replacement text of any entity referred to directly or indirectly in an
attribute value MUST NOT contain a <.
|
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)'' ?
|
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 written to my MySQL
database. I can later view this data back in the form.
One thing I've noticed happening is if I enter code such as < it
gets rewritten as < (ie the less-than sign). Now I don't want this to
happen, but something somewhere is...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |