設置元素的文本內容

Problem

You need to modify the text content of a HTML document.html

Solution

Use the text setter methods of Element:java

Element div = doc.select("div").first(); // <div></div>
div.text("five > four"); // <div>five &gt; four</div>
div.prepend("First ");
div.append(" Last");
// now: <div>First five &gt; four Last</div>

Discussion

The text setter methods mirror the HTML setter methods:node

The text should be supplied unencoded: characters like <> etc will be treated as literals, not HTML.spa

相關文章
相關標籤/搜索