【发布时间】:2013-11-11 04:06:07
【问题描述】:
所以我有一个 JEditorPane 来显示 HTML 页面。我编写了代码来通过 id 检索 HTML 元素。我无法获取它们的属性。
例如,HTML 页面中有<span id="0" class="insert">abc</span>。我想得到类名insert,给定它的id。
我的代码是这样的,
HTMLDocument html = (HTMLDocument) jeditor.getDocument();
String id = "0";
// make sure this id exists
if ((elem = html.getElement(id)) != null) {
// get the name of class in span element
String className = (String) elem.getAttributes().getAttribute("class");
...
}
这不起作用。但是,elem.getAttributes() 会返回以下内容,
LeafElement(content) 15,16
这不像 HTML 元素的一组属性。如何获取 HTML 元素的 class 属性?
谢谢!
【问题讨论】:
-
我已经放弃了。我不应该浪费生命从 Java 中的 HTML 获取类属性。
标签: java html swing jeditorpane htmleditorkit