Help designing reading/writing a xml-fileformat

Discussion in 'Python' started by Jacob Kroon, Dec 13, 2005.

  1. Jacob Kroon

    Jacob Kroon Guest

    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
    Jacob Kroon, Dec 13, 2005
    #1
    1. Advertising

  2. Jacob Kroon

    Alan Kennedy Guest

    [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.

    --
    alan kennedy
    ------------------------------------------------------
    email alan: http://xhaus.com/contact/alan
    Alan Kennedy, Dec 13, 2005
    #2
    1. Advertising

  3. Jacob Kroon

    Guest

    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/
    , Dec 13, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Hearn
    Replies:
    1
    Views:
    312
    avnrao
    Jun 30, 2004
  2. Dilip Bajaj via .NET 247
    Replies:
    2
    Views:
    493
    Peter Blum
    Mar 21, 2005
  3. Wim Deblauwe
    Replies:
    0
    Views:
    347
    Wim Deblauwe
    Aug 21, 2003
  4. Tony Girgenti

    Need help designing XML Dataset

    Tony Girgenti, Sep 16, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    411
    =?Utf-8?B?RGFuaWVsIEJyaXR0YWluIER1Z2dlcg==?=
    Sep 24, 2006
  5. Stanimir Stamenkov

    Re: Designing a recursive XML schema

    Stanimir Stamenkov, Sep 16, 2008, in forum: XML
    Replies:
    0
    Views:
    445
    Stanimir Stamenkov
    Sep 16, 2008
Loading...

Share This Page