Help designing reading/writing a xml-fileformat

J

Jacob Kroon

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
 
A

Alan Kennedy

[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/developerworks/library/xml-matters1/index.html
http://www-128.ibm.com/developerworks/library/xml-matters2/index.html

Revisiting xml_pickle and xml_objectify
http://www-128.ibm.com/developerworks/xml/library/x-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.
 
U

uche.ogbuji

Jacob said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top