[Zope] XML-RPC vs External method?

Irene Barg ibarg@as.arizona.edu
Wed, 01 Nov 2000 16:48:00 -0700


Hello all,

I have setup a query form to query a small MySQL database using
Zope.  It consists of:

1.  ZMySQL Database Connection (ZMySQLDA)
2.  ZSQL method
3.  A search interface.

Now, what I want is the user to have the option of viewing the
results in HTML or raw XML.  I think there can be two approaches
to this:  1. External method, or 2. XML-RPC.

1.  External method:  Replaces the ZMySQL database connection 
with an external Python function called 'mysqldb_XML', pieces
of which follow:

def mysqldb_XML(self,query):
    """
    Use a MySQL SAX driver to map relational data to XML.
    Hacked from PyXML saxdemo.py.  The MySQL driver is a modified 
    version of Sean McGrath's drv_mysql.py ("XML Processing with      
Python").
    """
    from xml.sax import saxexts, saxlib, saxutils, writer
    import sys,urllib
    
    #Our MySQLdb XML driver;
    driver="xml.sax.drivers.drv_mysqldb"
    .....
    out = sys.stdout;
    p=saxexts.make_parser(driver)
    dh=writer.PrettyPrinter(out,dtdinfo=info)
    try:
        p.setDocumentHandler(dh)
        return p.parse(query)
    except IOError,e:
        return in_sysID+": "+str(e)
    except saxlib.SAXException,e:
        return str(e)

Inside Zope, I get the ZSQL 'query' and do something like:

<dtml-call "RESPONSE.setHeader('content-type','text/xml')">
<dtml-in "mysqldb_XML(query)">
  <dtml-var sequence-item>
</dtml-in>


2.  XML-RPC:  It seems to me XML-RPC could do this too, but
I don't know how one would print out the raw XML response.
Could I have a Zope client request the ZSQL method above,
but instead of sending it to my output DTML method, I just
print the raw-XML stream?  Examples would be helpful:-)

It seems to me if XML-RPC already produces an XML formatted
stream, it would be more efficient to just use it (unless 
there is yet another way in Zope I'm not aware of).  Is it 
possible?  Is there any reason to want to use the external
method instead?

Thanks for your comments,

--irene 

------------------------------------------------------------------
Irene Barg			Email:	ibarg@as.arizona.edu
Steward Observatory		Phone:  520-621-2602
933 N. Cherry Ave.
University of Arizona		FAX:    520-621-1891
Tucson, AZ  85721		http://nickel.as.arizona.edu/~barg
------------------------------------------------------------------