如何去除java中Jtidy中的警告

发布于 2024-11-13 07:02:45 字数 752 浏览 8 评论 0原文

我在java中使用Jtidy解析器。

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

当我运行这个时,“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!

这些警告会自动显示在控制台上。但我不想要这些 运行后在控制台上显示警告

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

请帮助我,如何执行此操作,如何从控制台删除这些警告。

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 am getting 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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

草莓味的萝莉 2024-11-20 07:02:45

查看文档,我发现了一些可以实现您想要的功能的方法。

setShowErrorssetQuietsetErrout。您可能想尝试以下操作:

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

其中之一可能已经足够了,这些是我找到的所有选项。请注意,这只会隐藏消息,而不会对其执行任何操作。即使生成了错误,也可以使用 setForceOutput 来获取输出。

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.

酒解孤独 2024-11-20 07:02:45

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

如果您只是希望它们消失(与其他控制台输出一起),则使用 System.setOut() 和/或 System.setErr() 将输出发送到一个文件……或者一个黑洞。

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


或者,您可以将错误报告发送至[电子邮件受保护]。 :-)

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 [email protected]. :-)

清欢 2024-11-20 07:02:45
Writer out = new NullWriter();
PrintWriter dummyOut = new PrintWriter(out);
tidy.setErrout(dummyOut);
Writer out = new NullWriter();
PrintWriter dummyOut = new PrintWriter(out);
tidy.setErrout(dummyOut);
枫林﹌晚霞¤ 2024-11-20 07:02:45

查看文档,我发现另一种方法在这种特殊情况下对我来说似乎更好一些:setShowWarnings(boolean)。此方法将隐藏警告,但仍会引发错误。

欲了解更多信息,请看这里:
http://www.docjar.com/docs /api/org/w3c/tidy/Tidy.html#setShowWarnings(布尔值)

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)

别理我 2024-11-20 07:02:45

根据 Joost 的回答,我认为这是最好的解决方案:

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

这三个都是必要的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文