无法使用FlyingSaucer的XHTMLPanel查看Jsoup生成的HTML文档

时间:2012-07-01 09:49:45

标签: java webview jsoup flying-saucer

我只是使用Jsoup在Java上创建HTML文档。下面是代码的一部分

public static Document genDoc(String p) throws ProtocolException, IOException, InterruptedException, ParserConfigurationException{
   ........
   return Jsoup.parseBodyFragment(html);
}

完成文档生成后,我必须显示它。我只是使用FlyingSaucer的XHTML面板。这是代码

public static void main(String[] args) throws ProtocolException, IOException, InterruptedException, ParserConfigurationException{
   Document doc = genDoc("http://www.mangareader.net/93-1-11/naruto/chapter-1.html");
   XHTMLPanel xhp = new XHTMLPanel();
   xhp.setDocument(doc);
   ........
}

我认为类org.jsoup.nodes.Document继承自'org.w3c.dom.Document'。但是我错了。有没有什么方法可以传递'org.jsoup.nodes.Document'的对象来使用XHTMLPanel生成Web视图而不先将其转换为字符串或输入流或byte []?

1 个答案:

答案 0 :(得分:0)

我想围绕Strings没有办法,因为两个Lib都使用了不同的Document实现。

也许你可以为jsoup写一个转换器< - > w3c,但最简单的方法是使用字符串。

在您的情况下xhp.setDocument(doc.toString());应该没有任何问题。

(我正在使用它,例如.HTML - > PDF生成,到目前为止没有问题)