[Zope] XML-RPC vs External method?

Irene Barg ibarg@as.arizona.edu
Thu, 02 Nov 2000 09:39:18 -0700


Kapil,

Thank you for this simple solution!  I'm new to XML and Zope
and sometimes I get caught in learning too many new things
at once, we forget to think "simply":-)  Thanks to you, I
don't need to use either External method, or XML-RPC.  The
following simple DTML method works:

<dtml-call "RESPONSE.setHeader('content-type','text/xml')">
<?xml version="1.0"?>
<program>
<dtml-in get_all_programs>
     <row>
        <adassnum><dtml-var adassnum null=""></adassnum>
        <id><dtml-var id null=""></id>
        <title><dtml-var title null=""></title>
        <name_l><dtml-var name_l null=""></name_l>
        <name_f><dtml-var name_f null=""></name_f>
        <type><dtml-var type null=""></type>
      </row>
<dtml-else>
  <!--There was no data matching this query.-->
</dtml-in>
</program>

Thanks again!
--irene
Ender wrote:
> 
> if the xml format is simple you could just do it dtml, it would end up
> with some extra white space but it would still be valid.
> 
> a dtml method akin to
> 
> <?xml version="1.0"?>
> <dtml-in mysqlretrieve>
> <item>
>         <content><dtml-var content></content>
>         <squishy><dtml-var squishy></content>
> </item>
> </dtml-in>
> 
> kapil
> 
> Irene Barg wrote:
> >
> > 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
> > ------------------------------------------------------------------
> >
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://lists.zope.org/mailman/listinfo/zope
> > **   No cross posts or HTML encoding!  **
> > (Related lists -
> >  http://lists.zope.org/mailman/listinfo/zope-announce
> >  http://lists.zope.org/mailman/listinfo/zope-dev )

-- 

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