JTidy Node.findBody() — 如何使用?

发布于 2024-07-08 15:48:47 字数 312 浏览 6 评论 0原文

我正在尝试使用 JTidy 进行 XHTML DOM 解析,这似乎是相当违反直觉的任务。 特别是,有一个解析 HTML 的方法:

Node Tidy.parse(Reader, Writer)

并获取 > 我想,我应该使用该节点的位置,

Node Node.findBody(TagTable)

我应该在哪里获取该 TagTable 的实例? (构造函数是受保护的,我还没有找到工厂来生产它。)

我使用JTidy 8.0-SNAPSHOT。

I'm trying to do XHTML DOM parsing with JTidy, and it seems to be rather counterintuitive task. In particular, there's a method to parse HTML:

Node Tidy.parse(Reader, Writer)

And to get the <body /> of that Node, I assume, I should use

Node Node.findBody(TagTable)

Where should I get an instance of that TagTable? (Constructor is protected, and I haven't found a factory to produce it.)

I use JTidy 8.0-SNAPSHOT.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一笑百媚生 2024-07-15 15:48:47

我发现有更简单的方法来提取正文:

tidy = new Tidy();
tidy.setXHTML(true);
tidy.setPrintBodyOnly(true);

然后在读写器对上使用 tidy 。

应该如此简单。

I found there's much simpler method to extract the body:

tidy = new Tidy();
tidy.setXHTML(true);
tidy.setPrintBodyOnly(true);

And then use tidy on the Reader-Writer pair.

Simple as it should be.

酷遇一生 2024-07-15 15:48:47

您可以改用 parseDOM 方法,这会给您一个 org.w3c.dom.Document 返回:

Document document = Tidy.parseDOM(reader, writer);
Node body = document.getElementsByTagName("body").item(0);

You could use the parseDOM method instead, which would give you a org.w3c.dom.Document back:

Document document = Tidy.parseDOM(reader, writer);
Node body = document.getElementsByTagName("body").item(0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文