如何去除java中Jtidy中的警告
我在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看文档,我发现了一些可以实现您想要的功能的方法。
有
setShowErrors
、setQuiet
和setErrout
。您可能想尝试以下操作:其中之一可能已经足够了,这些是我找到的所有选项。请注意,这只会隐藏消息,而不会对其执行任何操作。即使生成了错误,也可以使用 setForceOutput 来获取输出。
Looking at the Documentation I found a few methods which may do what you want.
There is
setShowErrors
,setQuiet
andsetErrout
. You may want to try the following: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.如果您想将 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/orSystem.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]
. :-)查看文档,我发现另一种方法在这种特殊情况下对我来说似乎更好一些:
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)
根据 Joost 的回答,我认为这是最好的解决方案:
这三个都是必要的。
I think this is the nicest solution, based on the answer of Joost:
All three are necessary.