我正在尝试使用JTidy将HTML字符串转换为XHTML字符串,然后使用XMLWorkerHelper进行解析。我如何在字符串而不是文档中获得Tidy的输出?
我的代码是:
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setQuiet(true);
tidy.setShowWarnings(false);
org.w3c.dom.Document ppout = tidy.parseDOM(new ByteArrayInputStream(activityDtl.getPPDescription().toString().getBytes()), null);
System.out.println("ppout: " + ppout);
p6.add(new Chunk("Description: ", smallBold));
ElementList list1 = XMLWorkerHelper.parseToElementList(ppout, null);
for (Element element : list1) {
p6.add(element);
preface6.add(p6);
}
InputStream inputStream = new ByteArrayInputStream
(activityDtl.getPPDescription().getBytes("UTF-8"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Tidy tidy = new Tidy();
tidy.setXHTML(true);
tidy.setQuiet(true);
tidy.setShowWarnings(false);
tidy.parseDOM(inputStream, baos);
String ppDescription = baos.toString();
p6.add(new Chunk("Description: ", smallBold));
ElementList list1 = XMLWorkerHelper.parseToElementList(ppDescription, null);
for (Element element : list1) {
p6.add(element);
}
preface6.add(p6);