我能够解析HTML,但我希望从解析的HTML中提取警告消息,并将它们显示给用户。
下面是我的代码:
Tidy tidy = new Tidy();
StringBuffer StringBuffer1 = new StringBuffer("<b>Hello<u><b>I am tsting another one.....<i>another.....");
InputStream in = new ByteArrayInputStream(StringBuffer1.toString().getBytes("UTF-8"));
Writer stringWriter = new StringWriter();
tidy.setPrintBodyOnly(true);
tidy.setQuiet(true);
tidy.setShowWarnings(true);
tidy.setTidyMark(false);
tidy.setXHTML(true);
tidy.setXmlTags(false);
Node parsedNode = tidy.parse(in, stringWriter);
System.out.print(stringWriter.toString());发布于 2010-03-24 22:39:12
我在jTidy文档中注意到,从release r8 jTidy privdes TidyMessageListener接口开始,您可以实现html代码中的警告和错误通知。
这是doc
发布于 2013-06-17 23:54:08
您可以像这样设置错误输出流:
errorOutputStream = new java.io.ByteArrayOutputStream();
errorPrintWriter = new java.io.PrintWriter(errorOutputStream, true); //second param enables autoflush so you don't have to manually flush the printWriter
tidy.setErrout(errorPrintWriter);然后,当您需要查看错误时,errorOutputStream.toString();
https://stackoverflow.com/questions/2455980
复制相似问题