[Zope] Adding an XMLDocument instance Programmatically

Gaspard, Bradley S BRADLEY.S.GASPARD@saic.com
Mon, 24 Jul 2000 08:56:50 -0400


I am trying to write a python method which will programmatically create an
instance of an (existing) XML document.  (I am using Zope2.1.6 and
XMLDocument 1.0a6)  I am able to add an XML document by selecting the
XMLDocument from the available objects ... so XMLDocument is installed
correctly.

Essentially I have taken the 'add' method of XMLDocument and tried to turn
it into an external method.  [I was able to successfully do this for the
Parrot product so hopfully I am on the right track]

I can' t seem to get beyond importing Document (cannot import name
Document).  Do I need to import other modules?  Is this the best/only way to
do this??  Appreciate any help.

from Products.XMLDocument import Document

def add(self, id, title='', file='', REQUEST=None, submit=None):
    """
    Add a XML Document object with the contents of file.
    """
    ob=Document()
    ob.title=title
    ob.id=id
    if file: ob.parse(file)
    id=self._setObject(id, ob)
    if REQUEST is not None:
        try: u=self.DestinationURL()
        except: u=REQUEST['URL1']
        if submit==" Add and Edit ": u="%s/%s" % (u,quote(id))
        REQUEST.RESPONSE.redirect(u+'/manage_main')
    return ''

I appologize in advance if I have missed something obvious.

Brad