I am using JTidy to validate snippets of HTML generated in Java a rendering class. I would like to ignore certain warnings and errors.
(EDIT: On second thoughts I might not want to suppress errors)
For example, the following snippet that is generated:
<img src='/images/icon.gif'>
results in this warning:
line 5 column 7 - Warning: img lacks "alt" attribute
Can I configure JTidy to ignore specific checks such as this one?
The method I use to check is:
public static boolean isValidHtml(String htmlSnippet) {
String untestedHtml = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><HTML>" +
"<head><title>Wrapper HTML For Testing</title></head>" +
htmlSnippet +
"</HTML>";
final Tidy tidy = new Tidy();
final Writer writer = new StringWriter();
tidy.setErrout(new PrintWriter(writer, true));
tidy.parseDOM(new StringReader(untestedHtml), writer);
if (tidy.getParseErrors() > 0 || tidy.getParseWarnings() > 0) {
System.err.println(writer);
return false;
}
return true;
}