Sorry that's a bug on the docs and the code.

The TG2.0final way of doing it is.

    @expose()
    def test(self):
        pylons.response.headers['Content-Type'] = 'text/xml'
        return str

In TG2.1
it works with @expose(content_type='text/xml')
http://trac.turbogears.org/ticket/2280

and I hope we can get that into TG2.0.1

I'll appreciate it of someone could take the time to fix the docs.

On Wed, May 27, 2009 at 4:22 AM, rajasekhar911 <[email protected]> wrote:
>
> import pylons
> from tg.controllers import CUSTOM_CONTENT_TYPE
>
> @expose(content_type=CUSTOM_CONTENT_TYPE)
>    def test(self):
>        pylons.response.headers['Content-Type']  = 'text/xml'
>        message = ''' <Info>
>        <InfoNode NAME="Node1" TYPE="type"/>
>        <InfoNode NAME="Node2" TYPE="type"/>
>        <InfoNode NAME="Node3" TYPE="type" >
>        </Info>
>       '''
>     return message
>
> then call test.xml
>
>
> On Apr 17, 4:11 pm, Jasper <[email protected]> wrote:
>> I think this should do the trick:
>> ---------
>> @expose()
>> def test(self):
>>    message = ''' <Info>
>>  <InfoNode NAME="Node1" TYPE="type"/>
>>  <InfoNode NAME="Node2" TYPE="type"/>
>>  <InfoNode NAME="Node3" TYPE="type" >
>>  </Info>
>> '''
>>     return message
>> ---------
>> then call test.xml from the client
>>
>> Kind regards,
>>     Jasper
>>
>> On Apr 15, 4:15 pm,rajasekhar911<[email protected]> wrote:
>>
>> > Hi
>> > Thanks for the quick reply.
>> > My Xml format is like this ...
>> > <Info>
>> > <InfoNode NAME="Node1" TYPE="type"/>
>> > <InfoNode NAME="Node2" TYPE="type"/>
>> > <InfoNode NAME="Node3" TYPE="type" >
>> > </Info>
>> > I have this as a string variable.
>>
>> > I just want to pass this back as the response so that i can handle
>> > this with my ajax call as responseXML.
>>
>> > when i call response.set_header it gives an error
>> > AttributeError: 'function' object has no attribute 'set_header'
>>
>> > On Apr 15, 12:34 pm, "Diez B. Roggisch" <[email protected]> wrote:
>>
>> > >rajasekhar911schrieb:
>>
>> > > > Hi,
>>
>> > > > I have an application running in cherrypy. The exposed methods return
>> > > > an XML document which i parse to make changes to the UI.
>>
>> > > > I want to shift this application to TG2. How can I make the TG2
>> > > > controller to return the XML document?
>> > > > Can genshi do that for me? Or should I use the TGWebServices(http://
>> > > > pypi.python.org/pypi/TGWebServices)?
>>
>> > > I use genshi. It works roughly like this:
>>
>> > > from tg import response
>>
>> > > @expose() # no engine here, because we need control over content-type
>> > > def serve_xml(self, ...):
>> > >      template_content = load_template_content() # somehow get the
>> > > template, could be a string as well
>> > >      t = MarkupTemplate(template_content)
>> > >      args = create_argument_dict()
>> > >      response.set_header("Content-type", "whatever/you-like")
>> > >      return t.generate(**args).render()
>>
>> > > Diez
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to