Can I configure JTidy to ignore certain errors and warnings?

I am using JTidy to validate HTML fragments generated in Java by the render class. I would like to ignore certain warnings and errors .

(EDIT: Second, I don't want to suppress errors )

For example, the following snippet is created:

<img src='/images/icon.gif'>

      

results in this warning:

line 5 column 7 - Warning: img lacks "alt" attribute

Can JTidy be configured to ignore certain checks like this one?

The method I'm using to check:

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;
}

      

+3


source to share


1 answer


Use a config class to do this:



  Tidy tidy = new Tidy();
  tidy.setShowErrors(0);
  tidy.setForceOutput(true);

      

0


source







All Articles