[xwiki-users] how to generate XML from a velocity script page ?
Hello everybody, i need to use Ajax but i can not generate XML from a velocity script page. Here is a piece of my script : {{velocity}} $response.setContentType('application/xml') #set ($out = $response.getOutputStream()) $out.write("<?xml version='1.0' encoding='ISO-8859-1'?><test>test</test>") ... {{/velocity}} But my responseXML is null. I suppose that it's not the good way to generate XML from velocity. Thanks for your help. M. Canzerini
On 06/07/2012 09:28 AM, [email protected] wrote:
Hello everybody,
i need to use Ajax but i can not generate XML from a velocity script page. Here is a piece of my script : {{velocity}} $response.setContentType('application/xml') #set ($out = $response.getOutputStream()) $out.write("<?xml version='1.0' encoding='ISO-8859-1'?><test>test</test>") ... {{/velocity}}
But my responseXML is null.
I suppose that it's not the good way to generate XML from velocity.
Thanks for your help.
M. Canzerini
See this other thread: http://markmail.org/message/tjrnj6zy2n37blua Short summary, you should call flush() and close() on the stream after you're done writing data to it. -- Sergiu Dumitriu http://purl.org/net/sergiu/
On Thu, Jun 7, 2012 at 3:28 PM, <[email protected]> wrote:
Hello everybody,
i need to use Ajax but i can not generate XML from a velocity script page. Here is a piece of my script : {{velocity}} $response.setContentType('application/xml') #set ($out = $response.getOutputStream()) $out.write("<?xml version='1.0' encoding='ISO-8859-1'?><test>test</test>") ... {{/velocity}}
But my responseXML is null.
I suppose that it's not the good way to generate XML from velocity.
There is no #write(String) method in OutputStream but ServletOutputStream (which extends it and which is what you get in standard XWiki) provide a #print(String) method. but there is another issue. If you do only that XWiki will still send all the UI after your actual XML content so your XML parser will not like that too much. To avoid that you can use $xcontext.setFinished(true) so your script should looks like: {{velocity}} $response.setContentType('application/xml') #set ($out = $response.getOutputStream()) $out.print("<?xml version='1.0' encoding='ISO-8859-1'?><test>test</test>") ... $xcontext.setFinished(true) {{/velocity}}
Thanks for your help.
M. Canzerini
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
On Thu, Jun 7, 2012 at 3:43 PM, Sergiu Dumitriu <[email protected]> wrote:
On 06/07/2012 09:28 AM, [email protected] wrote:
Hello everybody,
i need to use Ajax but i can not generate XML from a velocity script page. Here is a piece of my script : {{velocity}} $response.setContentType('application/xml') #set ($out = $response.getOutputStream()) $out.write("<?xml version='1.0' encoding='ISO-8859-1'?><test>test</test>") ... {{/velocity}}
But my responseXML is null.
I suppose that it's not the good way to generate XML from velocity.
Thanks for your help.
M. Canzerini
See this other thread: http://markmail.org/message/tjrnj6zy2n37blua
Short summary, you should call flush() and close() on the stream after you're done writing data to it.
You can indeed also use $out.flush() and $out.close() instead of $xcontext.setFinished(true).
-- Sergiu Dumitriu http://purl.org/net/sergiu/
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
Now it works good thank you ! Mathieu On Thu, 7 Jun 2012 15:45:42 +0200, Thomas Mortagne <[email protected]> wrote:
On Thu, Jun 7, 2012 at 3:43 PM, Sergiu Dumitriu <[email protected]> wrote:
On 06/07/2012 09:28 AM, [email protected] wrote:
Hello everybody,
i need to use Ajax but i can not generate XML from a velocity script page. Here is a piece of my script : {{velocity}} $response.setContentType('application/xml') #set ($out = $response.getOutputStream()) $out.write("<?xml version='1.0' encoding='ISO-8859-1'?><test>test</test>") ... {{/velocity}}
But my responseXML is null.
I suppose that it's not the good way to generate XML from velocity.
Thanks for your help.
M. Canzerini
See this other thread: http://markmail.org/message/tjrnj6zy2n37blua
Short summary, you should call flush() and close() on the stream after you're done writing data to it.
You can indeed also use $out.flush() and $out.close() instead of $xcontext.setFinished(true).
-- Sergiu Dumitriu http://purl.org/net/sergiu/
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (3)
-
mathieu.canzerini@intech.lu -
Sergiu Dumitriu -
Thomas Mortagne