[Twisted-web] Re: xml library in twisted(need clarification)

Phil Christensen phil at bubblehouse.org
Wed Mar 5 00:47:44 EST 2008


On Mar 5, 2008, at 12:23 AM, Raj kumar wrote:
> Hi Phil,
> Thank you for the valuable reply.
> I need a clarification regarding this xml from you.
> from your reply i got to know is, the file which i wanted is not at  
> all any xml.
> Is it?
> Then let me tell you my problem....
> My (server-client)application will get players information from  
> different clients and the server will save this plyers information  
> in a *.xml file.
> And my server will send this file to clients when ever they need it.
> can you suggest me how to handle this situation?
> Do i need an xml?
> what you call the following format of my file other than xml?
> <game>
>     <player1>
>           <stuff>
>           </stuff>
>     </player1>
> </game>
>
> and one more thing is the problem with micrdom is i'm unable to  
> generate a tree stucture as above...everything it saves as a child  
> of  root like below..
> <game>
> <plyer1>
> <stuff>
> </stuff>
> </plyer1>
> </game>

I'm not really clear what the difference is supposed to be between  
those two samples. They seem to be semantically identical except for  
whitespace (and what I'm assuming is a typo with the plyer1 tag name).

Are you trying to output the XML in a "beautified" format?

As for whether XML is appropriate to use in this case, that's really  
up to you. It seems like you're trying to use XML as a communication  
protocol, which isn't particularly efficient, in the way that a F-16  
is not a particularly efficient way to get to the grocery store.

On the other hand, it also sounds like you control both ends of the  
wire. In that case, there's a myriad of other serialization protocols  
you might choose to transfer these attribute trees, including JSON,  
or Twisted's Perspective Broker.

> and to read all the elements from xml file again i have to use  
> domhelper. Because there is no function in microdom to read all the  
> elements in a single loop(other than read file line by line or to  
> get a specific element by getElement method).

I think you might want to try using getElementsByTagName(). It  
returns a list of matching nodes you can iterate through.

> Please suggest me what kind of xml stuff i'm using now? and any  
> better options for me?

If you're using this in the context of a Twisted app, you might as  
well use microdom, unless your XML starts getting complex and you  
need the speed of Expat or something. But again, XML is probably not  
your best choice here, except as an exercise.

-phil



More information about the Twisted-web mailing list