View Full Version : Controller that generates XML as view
Ellusionist
Jun 12th, 2007, 04:39 PM
I would like to have a controller that generates an XML file which displays as a view. In other words, the xml file will display in the browser.
Another app will then read in this XML file via the URL.
Could anybody point me in the right direction?
Thank You.
Jörg Heinicke
Jun 12th, 2007, 05:33 PM
So what's your actual problem? Writing the XML to the response stream? You might also have a look at the XsltView and see how it is supposed to work.
Jörg
jeroenverhagen
Jun 13th, 2007, 04:03 AM
If you use JSP's as your method of View (prob.) you can use this directive in your JSP to make it generate XML:
<%@ page language="java" contentType="text/xml" %>
regards,
Jeroen
jazman
Jun 13th, 2007, 06:49 AM
I'm having a similar problem. Except that I want to spit out a solid xml file that I will use for processing elsewhere. I had a look at the XsltView and I can see how you would build an xstl view from xml-like data. However having done little spring and very little xstl I am having difficulty understanding two things;
1) How is a xml file produced by the controller and not interpreted by an xstl template?
2) How is a solid xml file read by the controller and interpreted by an xstl template?
I have been through the example in the reference doc and I am still unsure how I should be doing this. Are there any other examples that anyone could provide to make it more clear.
Jörg Heinicke
Jun 13th, 2007, 08:44 AM
Ok, I had a look into XsltView and unfortunately it's not of much help since it expects a Source object.
I can recommend you Cocoon (http://cocoon.apache.org), but that's probably off-topic here and does not help you a lot at the moment :)
Jörg
jazman
Jun 13th, 2007, 08:59 AM
Ok, I had a look into XsltView and unfortunately it's not of much help since it expects a Source object.
I can recommend you Cocoon (http://cocoon.apache.org), but that's probably off-topic here and does not help you a lot at the moment :)
Jörg
Thank you for the recommendation. However I was looking for a spring mvc based solution. Is it just the case that there is a solution but just a lack of examples relating to one?
Jörg Heinicke
Jun 13th, 2007, 09:09 AM
Is it just the case that there is a solution but just a lack of examples relating to one?
Yes, you only need to create a Source object and so actually create some XML - be it DOM or whatever. So we are back at the beginning of the thread: How to create the XML?
Jörg
rpoetker
Jun 13th, 2007, 10:32 PM
Another possible approach is to implement a View class (probably extending org.springframework.web.servlet.view.AbstractView) and produce/write to response the XML in the render method.
You can use the org.springframework.web.servlet.view.ResourceBundl eViewResolver class to map the view name from your controller to your custom view class.
Also, to make the generation of the XML a little cleaner, you could use some binding library (like XML Beans) so at least you can build up the XML using objects and then toString the XMLBean. You will need to have the XML Schema if you use a binding library. This may or may not be appropriate depending on your requirements/situation.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.