从HTMLDocument获取各个元素的文本内容 [英] Get the text content of individual Elements from an HTMLDocument

查看:959
本文介绍了从HTMLDocument获取各个元素的文本内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 jTextPane ,将 HTMLEditorKit 设置为默认的 editorKit 。在 jTextPane 上调用 getDocument 返回一个 HTMLDocument 。我可以遍历本文档,浏览元素,但我似乎找不到一种实际获取单个元素的文本内容的方法。我知道在DOM中,每个元素上都有一个getTextContents(),但是我并没有使用W3C DOM。

I have a jTextPane that has HTMLEditorKit set as the default editorKit. Calling getDocument on the jTextPane returns an HTMLDocument. I can traverse through this Document, navigating around the elements, but I can't seem to find a way to actually get the text contents of individual elements. I know in the DOM, there is a getTextContents() on each element, but I'm not working with the W3C DOM.

推荐答案

p>当您浏览文档的 ElementIterator 时,此处显示,使用元素元素 getStartOffset() getEndOffset()计算调用 getText()所需的参数。

As you traverse the document's ElementIterator, shown here, use the getStartOffset() and getEndOffset() of each Element to calculate the parameters needed to call getText().

这篇关于从HTMLDocument获取各个元素的文本内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆