[Zope] Using ParsedXML from Python script

Sascha Welter zopelist at betabug.ch
Fri Feb 10 03:18:18 EST 2006

(Thu, Feb 09, 2006 at 12:00:08PM -0500) zope-request at zope.org wrote/schrieb/egrapse:
> From: Brian Sullivan <briansullivan at 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:

    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))

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?



More information about the Zope mailing list