如何在java中删除Jtidy中的警告

时间:2021-02-09 17:33:05

I am using Jtidy parser in java.

我在java中使用Jtidy解析器。

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 am getting some warnings as follows:

当我运行它时,“doc = new Tidy()。parseDOM(in,null);”我收到一些警告如下:

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 warnings are getting displayed automatically on console. But I don't want these warnings to be displayed on my console after running

这些警告将在控制台上自动显示。但我不希望这些警告在运行后显示在我的控制台上

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

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

请帮助我,如何做到这一点,如何从控制台中删除这些警告。

5 个解决方案

#1


9  

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:

有setShowErrors,setQuiet和setErrout。您可能想尝试以下操作:

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.

其中一个已经足够了,这些都是我找到的所有选项。请注意,这只是隐藏消息,而不是对它们做任何事情。即使生成了错误,也有setForceOutput来获取输出。

#2


5  

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

如果要将JTidy警告重定向到(例如)log4j记录器,请阅读此博客条目。

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.

如果你只是希望它们(以及其他控制台输出)消失,那么使用System.setOut()和/或System.setErr()将输出发送到文件......或黑洞。

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

对于JTidy版本8(或更高版本),Tidy.setMessageListener(TidyMessageListener)方法可以更优雅地处理消息。


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

或者,您可以向webmaster@yahoo.com发送错误报告。 :-)

#3


3  

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

#4


2  

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.

看一下这个文档,我找到了另一种方法,在这种特殊情况下对我来说似乎更好一点:setShowWarnings(boolean)。此方法将隐藏警告,但仍会抛出错误。

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

有关详细信息,请访问:http://www.docjar.com/docs/api/org/w3c/tidy/Tidy.html#setShowWarnings(boolean)

#5


0  

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

我认为这是最好的解决方案,基于Joost的答案:

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

All three are necessary.

这三个都是必要的。

#1


9  

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:

有setShowErrors,setQuiet和setErrout。您可能想尝试以下操作:

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.

其中一个已经足够了,这些都是我找到的所有选项。请注意,这只是隐藏消息,而不是对它们做任何事情。即使生成了错误,也有setForceOutput来获取输出。

#2


5  

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

如果要将JTidy警告重定向到(例如)log4j记录器,请阅读此博客条目。

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.

如果你只是希望它们(以及其他控制台输出)消失,那么使用System.setOut()和/或System.setErr()将输出发送到文件......或黑洞。

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

对于JTidy版本8(或更高版本),Tidy.setMessageListener(TidyMessageListener)方法可以更优雅地处理消息。


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

或者,您可以向webmaster@yahoo.com发送错误报告。 :-)

#3


3  

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

#4


2  

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.

看一下这个文档,我找到了另一种方法,在这种特殊情况下对我来说似乎更好一点:setShowWarnings(boolean)。此方法将隐藏警告,但仍会抛出错误。

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

有关详细信息,请访问:http://www.docjar.com/docs/api/org/w3c/tidy/Tidy.html#setShowWarnings(boolean)

#5


0  

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

我认为这是最好的解决方案,基于Joost的答案:

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

All three are necessary.

这三个都是必要的。