我能够解析 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());
最佳答案
我在 jTidy 文档中注意到,从版本 r8 jTidy privdes TidyMessageListener 接口(interface)开始,您可以实现 html 代码中的警告和错误通知。
这是doc
关于html - 如何使用 JTidy 从解析的 HTML 中获取错误/警告消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2455980/