したがって、HTML ページを表示するための JEditorPane があります。ID で HTML 要素を取得するコードを作成しました。それらの属性を取得するのに問題があります。
たとえば<span id="0" class="insert">abc</span>
、HTMLページにあります。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 要素のクラス属性を取得するにはどうすればよいですか?
ありがとう!