みなさんこんにちは。 HTMLコードをデータベースに保存しようとしていて、SHEF(Swing HTML Editor Framework)を使用していますが、大きな問題があります。通常、生成されたHTMLは次のようである:JSoupまたはHTMLCleanerを使用してHTMLコードを短縮する方法
<div>
This is the first paragraph
</div>
<div>
This is the second paragraph.
</div>
<div>
This is the last paragraph.
</div>
は、私が「クリーン」なhtmlコードとは、結果が、この代わりのように見えるようにしたい:
<div>
This is the first paragraph
<br>
This is the second paragraph.
<br>
This is the last paragraph.
</div>
私はHTMLCleanerとJSoupを使用しようとしましたが、私はそれを作っていない。私はJSoupが
<div>
This is the first paragraph
</div>
<div>
</div>
<div>
This is the last paragraph.
</div>
になるように動作させることができます
<div>
This is the first paragraph
</div>
<br>
<div>
This is the last paragraph.
</div>
これは私が使用しJSoupコード:
Document source = Jsoup.parse(sourceString);
// For each element
for(Element el: source.select("*")) {
if(el.children().isEmpty() && !el.hasText() && el.isBlock()) {
el.replaceWith(new Element(Tag.valueOf("br"), ""));//replace empty tags with newline
}
}
return source.body().html();
短い生成されたHTMLコードを作るためにどのような方法があります?ありがとう!
HTMLのクリーニング/編集は、Swingとは関係ありません。アプリだけのためにSwingタグを追加しないでください。 Swing APIの一部を使用しています。 –