473,324 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Module for converting XML to Python object(s)?

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
Jul 18 '05 #1
8 2908
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"
Jul 18 '05 #2
[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" <fr*****@pythonware.com>
Date: Fri, 18 Jun 2004 17:07:43 +0200
Subject: ANN: ElementTree 1.2 final (june 18, 2004)
To: py******************@python.org
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/listi...-announce-list

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

--
François Pinard http://www.iro.umontreal.ca/~pinard
Jul 18 '05 #3
"Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message news:<ot*************@bignews5.bellsouth.net>...
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
Jul 18 '05 #4

"Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message
news:ot*************@bignews5.bellsouth.net...
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
Jul 18 '05 #5
"Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message news:<ot*************@bignews5.bellsouth.net>...
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/developerwork.../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/xm...x-think25.html
A survey of XML standards -
http://www-106.ibm.com/developerwork...rary/x-stand4/
Jul 18 '05 #6
François Pinard <pi****@iro.umontreal.ca> wrote in message news:<ma**************************************@pyt hon.org>...
[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" <fr*****@pythonware.com>
Date: Fri, 18 Jun 2004 17:07:43 +0200
Subject: ANN: ElementTree 1.2 final (june 18, 2004)
To: py******************@python.org
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/developerwork.../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/xm...x-think25.html
A survey of XML standards -
http://www-106.ibm.com/developerwork...rary/x-stand4/
Jul 18 '05 #7
"Colin Brown" <cb****@metservice.com> wrote in message news:<41********@news.iconz.co.nz>...
"Robert Oschler" <no_replies@fake_email_address.invalid> wrote in message
news:ot*************@bignews5.bellsouth.net...
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/developerwork.../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/xm...x-think25.html
A survey of XML standards -
http://www-106.ibm.com/developerwork...rary/x-stand4/
Jul 18 '05 #8
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
Jul 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Jeff Wagner | last post by:
Is there a Python module or method that can convert between numeric bases? Specifically, I need to convert between Hex, Decimal and Binary such as 5Ah = 90d = 01011010b. I searched many places...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
5
by: jeremy.d.brewer | last post by:
Hi, I'm rather new to Python, and I've just written my first Python C module. I was wondering if some more experience Pythonista would look over what I've written and given me some pointers (or...
14
by: dananrg | last post by:
Been using the ODBC module for Python 2.1 (Win32) and had another question. When I return data from date columns, it's in a strange object form, e.g. <something or other> (don't have the output in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.