Module for converting XML to Python object(s)?

Discussion in 'Python' started by Robert Oschler, Aug 1, 2004.

  1. Has anybody seen a Python module that will take an XML document (not a
    colossal one), and convert it to a Python nested class object? I'm
    basically looking for something that would allow me to parse an XML document
    (not tokenize it like SAX or make it into an XPath accessible DOM object
    like others), directly into a nested Python object so I could access
    everything through Python class attribute references.

    Thanks.
    --
    Robert
     
    Robert Oschler, Aug 1, 2004
    #1
    1. Advertising

  2. In data Sun, 1 Aug 2004 17:42:14 -0400, Robert Oschler ha scritto:

    > Has anybody seen a Python module that will take an XML document (not a
    > colossal one), and convert it to a Python nested class object?


    Maybe this can help you:
    http://xmlobject.base-art.net/

    --
    Lawrence (l dot oluyede at virgilio dot it)
    "In IE we trust"
     
    Lawrence Oluyede, Aug 1, 2004
    #2
    1. Advertising

  3. [Robert Oschler]
    > Has anybody seen a Python module that will take an XML document (not a
    > colossal one), and convert it to a Python nested class object?


    You might want to check this announcement:

    From: "Fredrik Lundh" <>
    Date: Fri, 18 Jun 2004 17:07:43 +0200
    Subject: ANN: ElementTree 1.2 final (june 18, 2004)
    To:
    Newsgroups: comp.lang.python.announce

    The Element type is a simple but flexible container object,
    designed to store hierarchical data structures, such as
    simplified XML infosets, in memory. The ElementTree package
    provides a Python implementation of this type, plus code to
    serialize element trees to and from XML files.

    The 1.2 release adds limited support for XPath and XInclude, and
    also fixes a number of serialization bugs, mostly related to
    extensive use of namespaces and unicode in tags and attribute
    names. For a complete list of changes, see the CHANGES document
    in the source kit.

    You can get the ElementTree toolkit from:

    http://effbot.org/downloads

    Documentation, articles, and some code samples (including an
    XML-RPC unmarshaller in 16 lines) are available from:

    http://effbot.org/zone/element.htm

    enjoy /F

    --
    http://mail.python.org/mailman/listinfo/python-announce-list

    Support the Python Software Foundation:
    http://www.python.org/psf/donations.html

    --
    Fran├žois Pinard http://www.iro.umontreal.ca/~pinard
     
    =?iso-8859-1?Q?Fran=E7ois?= Pinard, Aug 1, 2004
    #3
  4. Robert Oschler

    Jim Hefferon Guest

    "Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message news:<otdPc.224$>...
    > Has anybody seen a Python module that will take an XML document (not a
    > colossal one), and convert it to a Python nested class object?

    Perhaps
    http://www.rexx.com/~dkuhlman/gnosis_generateds.html
    would help?

    Jim
     
    Jim Hefferon, Aug 2, 2004
    #4
  5. Robert Oschler

    Colin Brown Guest

    "Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message
    news:eek:tdPc.224$...
    > Has anybody seen a Python module that will take an XML document (not a
    > colossal one), and convert it to a Python nested class object?


    Also pyRXP ref: http://www.reportlab.org/pyrxp.html

    Colin Brown
    PyNZ
     
    Colin Brown, Aug 4, 2004
    #5
  6. Robert Oschler

    Uche Ogbuji Guest

    "Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message news:<otdPc.224$>...
    > Has anybody seen a Python module that will take an XML document (not a
    > colossal one), and convert it to a Python nested class object? I'm
    > basically looking for something that would allow me to parse an XML document
    > (not tokenize it like SAX or make it into an XPath accessible DOM object
    > like others), directly into a nested Python object so I could access
    > everything through Python class attribute references.


    There is a metric ton of these "data bindings". See:

    http://www.xml.com/pub/a/2003/06/11/py-xml.html
    http://www.xml.com/pub/a/2003/07/02/py-xml.html
    http://www.xml.com/pub/a/2003/08/13/py-xml.html
    http://www.xml.com/pub/a/2003/12/17/py-xml.html

    Based on your description, your best bets are generate_ds, gnosis
    objectify, xmltramp and Anobind.

    Good luck, and do report back on your experiences.


    --
    Uche Ogbuji Fourthought, Inc.
    http://uche.ogbuji.net http://4Suite.org http://fourthought.com
    Perspective on XML: Steady steps spell success with Google -
    http://www.adtmag.com/article.asp?id=9663
    Use XML namespaces with care -
    http://www-106.ibm.com/developerworks/xml/library/x-namcar.html
    Managing XML libraries - http://www.adtmag.com/article.asp?id=9160
    Commentary on "Objects. Encapsulation. XML?" -
    http://www.adtmag.com/article.asp?id=9090
    Harold's Effective XML -
    http://www.ibm.com/developerworks/xml/library/x-think25.html
    A survey of XML standards -
    http://www-106.ibm.com/developerworks/xml/library/x-stand4/
     
    Uche Ogbuji, Aug 9, 2004
    #6
  7. Robert Oschler

    Uche Ogbuji Guest

    Fran├žois Pinard <> wrote in message news:<>...
    > [Robert Oschler]
    > > Has anybody seen a Python module that will take an XML document (not a
    > > colossal one), and convert it to a Python nested class object?

    >
    > You might want to check this announcement:
    >
    > From: "Fredrik Lundh" <>
    > Date: Fri, 18 Jun 2004 17:07:43 +0200
    > Subject: ANN: ElementTree 1.2 final (june 18, 2004)
    > To:
    > Newsgroups: comp.lang.python.announce
    >
    > The Element type is a simple but flexible container object,
    > designed to store hierarchical data structures, such as
    > simplified XML infosets, in memory. The ElementTree package
    > provides a Python implementation of this type, plus code to
    > serialize element trees to and from XML files.


    ElementTree rocks, but is not really what I understood the OP's
    request to be. It seems he wants specialized classes matching the XML
    vocabulary, e.g.

    print html.head.title

    You can't really do this with ElementTree. This is the preserve of a
    different class of XML libraries, called data bindings. I discussed
    data bindings I know of in my previous response to the OP. Oluyede
    reminded me of XMLObject. Also, both Eric van der Vlist and Guido van
    Rossum himself have done recent work in data bindings for XML/Python.
    Neither's work is packaged for public release yet, though.


    --
    Uche Ogbuji Fourthought, Inc.
    http://uche.ogbuji.net http://4Suite.org http://fourthought.com
    Perspective on XML: Steady steps spell success with Google -
    http://www.adtmag.com/article.asp?id=9663
    Use XML namespaces with care -
    http://www-106.ibm.com/developerworks/xml/library/x-namcar.html
    Managing XML libraries - http://www.adtmag.com/article.asp?id=9160
    Commentary on "Objects. Encapsulation. XML?" -
    http://www.adtmag.com/article.asp?id=9090
    Harold's Effective XML -
    http://www.ibm.com/developerworks/xml/library/x-think25.html
    A survey of XML standards -
    http://www-106.ibm.com/developerworks/xml/library/x-stand4/
     
    Uche Ogbuji, Aug 9, 2004
    #7
  8. Robert Oschler

    Uche Ogbuji Guest

    "Colin Brown" <> wrote in message news:<41105a9c$>...
    > "Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message
    > news:eek:tdPc.224$...
    > > Has anybody seen a Python module that will take an XML document (not a
    > > colossal one), and convert it to a Python nested class object?

    >
    > Also pyRXP ref: http://www.reportlab.org/pyrxp.html


    PyRXPU (the only useful part of PyRXP) is not really what the OP was
    asking for. It creates lists and dicts rather than actual element
    structures that can be accessed using the natural vocabulary from the
    XML (e.g. "print html.head.title").


    --
    Uche Ogbuji Fourthought, Inc.
    http://uche.ogbuji.net http://4Suite.org http://fourthought.com
    Perspective on XML: Steady steps spell success with Google -
    http://www.adtmag.com/article.asp?id=9663
    Use XML namespaces with care -
    http://www-106.ibm.com/developerworks/xml/library/x-namcar.html
    Managing XML libraries - http://www.adtmag.com/article.asp?id=9160
    Commentary on "Objects. Encapsulation. XML?" -
    http://www.adtmag.com/article.asp?id=9090
    Harold's Effective XML -
    http://www.ibm.com/developerworks/xml/library/x-think25.html
    A survey of XML standards -
    http://www-106.ibm.com/developerworks/xml/library/x-stand4/
     
    Uche Ogbuji, Aug 9, 2004
    #8
  9. Robert Oschler <no_replies@fake_email_address.invalid> wrote:
    > Has anybody seen a Python module that will take an XML document (not a
    > colossal one), and convert it to a Python nested class object? I'm


    I have something similar implemented in the "ext-rep" module of the
    "pydesign" package. Here is an excerpt from the documentation:

    XTree is a class to create and manipulate a labeled rooted tree data
    structure whose underlying raw data structure is a tree whose nodes are
    tuples of the structure:

    (node_name, {dictionary of attributes}, [list of children])

    The dictionary of attributes represents the label associated with the
    node. This raw tree is not accessed directly, however, but through the
    XTree object's interface. XTree, in fact, is a lazy recursive wrapper
    around the raw structure and hides the implementation details. From the
    user's point of view, the internal nodes of the tree presented this way
    are of the XTree type. The leaves of the tree are either childless XTree
    objects or some particular Python data types. Currently, the following
    Python data types can be used for leaves: integer, floating point,
    string, list of integers.

    The module is specialized to a particular highly structured XML
    document, but it should not be difficult to modify it for your needs.
    The user can read the whole XML document in one step or alternatively as
    a "stream" of sub XTree-s.

    In fact, I have found this streaming Reader (parser + converter)
    solution so useful that I am planning to make the module into a general
    parameterizable module.

    You can find documentation and the package at:

    http://designtheory.org/software/pydesign/

    -- ,
    Peter Dobcsanyi
     
    Peter Dobcsanyi, Aug 9, 2004
    #9
    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. jkflens
    Replies:
    2
    Views:
    1,546
    jkflens
    May 30, 2006
  2. Mothra
    Replies:
    5
    Views:
    495
    Dennis Lee Bieber
    Apr 15, 2005
  3. Maric Michaud
    Replies:
    0
    Views:
    7,221
    Maric Michaud
    Jun 24, 2006
  4. deepak
    Replies:
    2
    Views:
    1,741
    deepak
    Feb 14, 2008
  5. KevinSimonson
    Replies:
    6
    Views:
    651
Loading...

Share This Page