how to remove the warnings in Jtidy in java

天涯浪子 提交于 2019-12-01 06:44:49

Looking at the Documentation I found a few methods which may do what you want.

There is setShowErrors, setQuiet and setErrout. You may want to try the following:

Tidy tidy = new Tidy();
tidy.setShowErrors(0);
tidy.setQuiet(true);
tidy.setErrout(null);
doc = tidy.parseDOM(in, null);

One of them may be enough already, these were all the options I found. Note that this will simply hide the messages, not do anything about them. There is also setForceOutput to get the output, even if errors were generated.

If you want to redirect the JTidy warnings to (say) a log4j logger, read this blog entry.

If you simply want them to go away (along with other console output), then use System.setOut() and/or System.setErr() to send the output to a file ... or a black hole.

For JTidy release 8 (or later), the Tidy.setMessageListener(TidyMessageListener) method deals with the messages more gracefully.


Alternatively, you could send a bug report to webmaster@yahoo.com. :-)

Writer out = new NullWriter();
PrintWriter dummyOut = new PrintWriter(out);
tidy.setErrout(dummyOut);

Looking at the documentation I found another method that seems a bit nicer to me in this particular case: setShowWarnings(boolean). This method will hide the warnings, but errors will still be thrown.

For more info look here: http://www.docjar.com/docs/api/org/w3c/tidy/Tidy.html#setShowWarnings(boolean)

I think this is the nicest solution, based on the answer of Joost:

Tidy tidy = new Tidy();
tidy.setShowErrors(0);
tidy.setShowWarnings(false);
tidy.setQuiet(true);

All three are necessary.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!