I'm writing an application that outputs xml and I'm using a jsp to do it (in eclipse). It works fine, but the jsp editor complains about the xml tags. Is there a way to convince the jsp editor to validate xml instead of html?
A:
Oh, I misread that entirely.
You can turn of JSP format / verification in Eclipse properties.
In addition ensure you have <%@ page contentType="application/rss+xml" %>
in your JSP.
Previous answer.
1) Create an XML util class that has methods to abstract the generation of XML, auto-handle pretty-print, etc. I could see it having public methods like:
public void init();
// <tagname> and <tagname />
public void openTag(String tagname, boolean close);
// <tagname x="y">
public void openTag(String tagname, Map<String, String> attributes, boolean close);
// </tagname>
public void closeTag(String tagname);
// <tagname>value</tagname>
public void valueTag(String tagname, String value);
public void valueTag(String tagname, Map<String, String> attributes, String value);
public String getXML();
or you could have each operation return a String and manage the StringBuilder yourself.
2) Why are you generating XML in a JSP class, which should be used for presentation?
JeeBee
2008-12-03 13:51:40
Because I'm presenting an rss feed and it seems the easiest way. I'm sure there are more complex ways, but I generally prefer simplicity unless there's a good reason.
stu
2008-12-03 14:41:37
Yeah, I had misread what you were doing there. I don't know if you can add a content type and a pointer to the DTD in the document to help, or maybe you are already. Does this help? http://java.sun.com/developer/technicalArticles/javaserverpages/rss_utilities/
JeeBee
2008-12-03 14:45:33
And at the top of your JSP: <%@ page contentType="application/rss+xml" %>
JeeBee
2008-12-03 14:51:52