简体   繁体   中英

Can I use eclipse xml validator in a jsp?

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?

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM