Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Help designing reading/writing a xml-fileformat

Reply
Thread Tools

Help designing reading/writing a xml-fileformat

 
 
Jacob Kroon
Guest
Posts: n/a
 
      12-13-2005
I'm writing a block-diagram editor, and could use some tips about
writing/reading
diagrams to/from an xml file format. The basic layout of my code :

class Diagram {
Blocks blocks[]
}

class Block {
int x, y
}

class Square(Block) {
int width, height
}

class Circle(Block) {
int radius
}

I'd like to be able to output something similar to this:

<diagram>
<square x='12' y='34' width='50' height='40'/>
<circle x='40' y='60' radius='20/>
</diagram>

One idea I had was to make Diagram and Block derive from
xml.dom.minidom.Element,
and then somehow catch when I set an attribute, so that setAttribute()
gets called with correct
arguments. Perhaps then I could just do a simple diagram.toprettyxml().

Anyone have a good idea on how to approach this problem ?
(I do not want to use the pickle module)

/Jacob Kroon

 
Reply With Quote
 
 
 
 
Alan Kennedy
Guest
Posts: n/a
 
      12-13-2005
[Jacob Kroon]
> I'm writing a block-diagram editor, and could use some tips about
> writing/reading
> diagrams to/from an xml file format.


I highly recommend reading David Mertz excellent articles on the
conversion of objects to xml and vice-versa.

On the 'Pythonic' treatment of XML documents as objects, I + II
http://www-128.ibm.com/developerwork...rs1/index.html
http://www-128.ibm.com/developerwork...rs2/index.html

Revisiting xml_pickle and xml_objectify
http://www-128.ibm.com/developerwork...matters11.html

> Anyone have a good idea on how to approach this problem ?
> (I do not want to use the pickle module)


Why not the pickle module? XML-format pickles are a good solution to
your problem, IMHO.

--
alan kennedy
------------------------------------------------------
email alan: http://xhaus.com/contact/alan
 
Reply With Quote
 
 
 
 
uche.ogbuji@gmail.com
Guest
Posts: n/a
 
      12-13-2005
Jacob Kroon wrote:
> I'm writing a block-diagram editor, and could use some tips about
> writing/reading
> diagrams to/from an xml file format. The basic layout of my code :
>
> class Diagram {
> Blocks blocks[]
> }
>
> class Block {
> int x, y
> }
>
> class Square(Block) {
> int width, height
> }
>
> class Circle(Block) {
> int radius
> }
>
> I'd like to be able to output something similar to this:
>
> <diagram>
> <square x='12' y='34' width='50' height='40'/>
> <circle x='40' y='60' radius='20/>
> </diagram>


[SNIP]

> Anyone have a good idea on how to approach this problem ?
> (I do not want to use the pickle module)


How about an XML pickle? PyXML has such a module. WDDX, also in
PyXML, is another option.

--
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://fourthought.com
http://copia.ogbuji.net http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help in designing normalization ledinhkha@gmail.com VHDL 4 09-06-2006 10:10 AM
help me in designing the network Johny Cisco 0 11-08-2005 12:24 PM
Need help designing a way to flip through articles =?Utf-8?B?dHBlcnJp?= ASP .Net 1 06-27-2005 02:56 PM
Help Help!!! In designing ASP.NET Interactive/ Calculative Application. Dilip Bajaj via .NET 247 ASP .Net 2 03-21-2005 04:42 PM
Report designing help.. Support ASP .Net 0 07-07-2004 12:31 PM



Advertisments