Get the text content of individual Elements from an HTMLDocument

*爱你&永不变心* 提交于 2020-01-14 10:23:45

问题


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.


回答1:


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().



来源:https://stackoverflow.com/questions/9559997/get-the-text-content-of-individual-elements-from-an-htmldocument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!