Rendering page as XML or JSON?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Rendering page as XML or JSON?

Conrad Taylor
Hi, is there an easy to render a page as XML/JSON instead of HTML?  For example, I would like to send back the collection as XML document.  Thus, I'm looking for something similar to Rails respond_to whereas

def show
@order = Order.find(params[:id])
respond_to do |format| format.html # show.rhtml format.xml { render :xml => @order.to_xml }
format.js { render :json => @order.to_json }
end
end

Thanks in advance,

-Conrad


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: Rendering page as XML or JSON?

Ramon Leon-5
>
> Hi, is there an easy to render a page as XML/JSON instead of
> HTML?  For example, I would like to send back the collection
> as XML document.  Thus, I'm looking for something similar to
> Rails respond_to whereas
>
> def show
> @order = Order.find(params[:id])
>
> respond_to do |format| format.html # show.rhtml format.xml {
> render :xml => @order.to_xml } format.js { render :json =>
> @order.to_json } end end
>
>
> Thanks in advance,
>
>
> -Conrad

You can do something like this, replacing sixxString with your own xml
building method for something prettier, and #beXml with whatever param name
you want to kick it off...

self session currentRequest at: #beXml ifPresent: [ : it |
    self session returnResponse:
        (WAResponse new
            contentType: 'text/xml' ;
            contents: someObject sixxString readStream ;
            yourself)]

If you have a json builder, it'd be similar.  If there's a better way, I
don't know it.

Ramon Leon
http://onsmalltalk.com

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rendering page as XML or JSON?

Michael Lucas-Smith-3

> self session currentRequest at: #beXml ifPresent: [ : it |
>     self session returnResponse:
>         (WAResponse new
>             contentType: 'text/xml' ;
>             contents: someObject sixxString readStream ;
>             yourself)]
>  
If you make your own WACanvas subclass too you can do something like this:

    response := Seaside.WAResponse new.
    response contentType: 'application/atom+xml'.
    response nextPutAll: '<?xml version="1.0" encoding="utf-8"?>'.
    atom := SeasideAtom.AtomCanvas new.
    atom context: html context.
    html context document stream: response stream.
    ... do stuff with our new atom canvas ...
    self session returnResponse: response.

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rendering page as XML or JSON?

Conrad Taylor
Hi ALL, thanks for the information and I'll really appreciate it.  At this time, I'm looking to convert a Rails application to Seaside.

-Conrad

On Thu, Apr 17, 2008 at 1:52 PM, Michael Lucas-Smith <[hidden email]> wrote:

self session currentRequest at: #beXml ifPresent: [ : it |    self session returnResponse:        (WAResponse new
           contentType: 'text/xml' ;
           contents: someObject sixxString readStream ;
           yourself)]
 
If you make your own WACanvas subclass too you can do something like this:

  response := Seaside.WAResponse new.
  response contentType: 'application/atom+xml'.
  response nextPutAll: '<?xml version="1.0" encoding="utf-8"?>'.
  atom := SeasideAtom.AtomCanvas new.
  atom context: html context.
  html context document stream: response stream.
  ... do stuff with our new atom canvas ...
  self session returnResponse: response.


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside