Re: [Zope] Using ParsedXML from Python script
(Thu, Feb 09, 2006 at 12:00:08PM -0500) zope-request@zope.org wrote/schrieb/egrapse:
From: Brian Sullivan <briansullivan@gmail.com> Subject: [Zope] Using ParsedXML from Python script
I am attempting to extract information from a ParsedXML object using Python script.
I can't seem to get my mind around exactly how this works. Can anyone point non trivial examples in Python of maniupulating a ParsedXML object?
This is from a class that is based on ParsedXML.ParsedXML, caveat: It's code from an old project that isn't maintained and maybe it was done suboptimal anyway :-) def get_Status(self): doc = self.documentElement status = doc.getElementsByTagName('Status')[0].getAttribute('Number') return { 'Status':str(status), 'Schema':'ImageID' } another one: def get_photo_count(self): return self.documentElement.getElementsByTagName('Photo').length the manage_addXY method of that object has something like this inside: try: b = NetSelection(id, file, useNamespaces, contentType) except expat.error, e: ... do things here and the class has no explicit __init__ method, so likely we got that from the ParsedXML.ParsedXML base class. also there seems to be stuff that adds/changes things in some methods: if not new_node: new_node = this_Photo.appendChild(doc.createElement(Network_Description)) or: def _set_description_on_node ( self, node, Description_Dictionary ): ''' "sets" the contents of a Dictionary into an XML node ''' for fred in Description_Dictionary.keys(): node.setAttribute( fred, Description_Dictionary[ fred ] ) Is that the kind of thing you were looking for? Regards, Sascha
Hi Brian, unless it is mandatory for you to use ParsedXML for your XML needs, you might want to check out Uche Ogbuji's Amara Toolkit ( http://uche.ogbuji.net/tech/4suite/amara/ ). It provides a much more "pythonic" way of dealing with XML. Regards, Patrick. On 2/10/06, Brian Sullivan <briansullivan@gmail.com> wrote:
On 2/10/06, Sascha Welter <zopelist@betabug.ch> wrote:
Is that the kind of thing you were looking for?
Better than what I have now -- it might get me over the initial hump -- thanks. _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On 2/10/06, Patrick Decat <pdecat@gmail.com> wrote:
Hi Brian,
unless it is mandatory for you to use ParsedXML for your XML needs, you might want to check out Uche Ogbuji's Amara Toolkit ( http://uche.ogbuji.net/tech/4suite/amara/ ). It provides a much more "pythonic" way of dealing with XML.
Well maybe more pythonic -- but seemingly not zopic? My Python use is in Zope. Or am I missing something?
I use it with Zope and Zope/CMF Content (Documents, Files, ExternalFiles) from a custom filesystem product. Regards, Patrick. On 2/10/06, Brian Sullivan <briansullivan@gmail.com> wrote:
On 2/10/06, Patrick Decat <pdecat@gmail.com> wrote:
Hi Brian,
unless it is mandatory for you to use ParsedXML for your XML needs, you might want to check out Uche Ogbuji's Amara Toolkit ( http://uche.ogbuji.net/tech/4suite/amara/ ). It provides a much more "pythonic" way of dealing with XML.
Well maybe more pythonic -- but seemingly not zopic?
My Python use is in Zope. Or am I missing something? _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
participants (3)
-
Brian Sullivan -
Patrick Decat -
Sascha Welter