How to remove warnings in jtidy in java

I am using Jtidy parser in java.

URL url = new URL("www.yahoo.com"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); InputStream in = conn.getInputStream(); doc = new Tidy().parseDOM(in, null); 

when I run this, "doc = new Tidy (). parseDOM (in, null);" I get some warnings as follows:

 Tidy (vers 4th August 2000) Parsing "InputStream" line 140 column 5 - Warning: <table> lacks "summary" attribute InputStream: Doctype given is "-//W3C//DTD XHTML 1.0 Strict//EN" InputStream: Document content looks like HTML 4.01 Transitional 1 warnings/errors were found! 

These alerts are displayed automatically on the console. But I do not want these warnings to be displayed on my console after starting

 doc = new Tidy().parseDOM(in, null); 

Please help me how to do this, how to remove these warnings from the console.

+4
source share
5 answers

Looking at the documentation, I found several methods that can do what you want.

There is setShowErrors , setQuiet and setErrout . You can 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 already be enough, these were all the options that I found. Note that this will simply hide the messages, and not do anything about them. There is also setForceOutput to get the result, even if errors were generated.

+8
source

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

If you just want them to leave (along with another console output), use System.setOut() and / or System.setErr() to send the output to a file ... or a black hole.

For version 8 (or later) JTidy, the Tidy.setMessageListener(TidyMessageListener) method handles messages more competently.


Alternatively, you can send a bug report to webmaster@yahoo.com . webmaster@yahoo.com

+5
source
 Writer out = new NullWriter(); PrintWriter dummyOut = new PrintWriter(out); tidy.setErrout(dummyOut); 
+3
source

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

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

+2
source

I think this is the nicest solution based on Joost's answer:

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

All three are necessary.

0
source

All Articles