I want to replace some elements in HTML files, leaving everything else unchanged.
Document doc = Jsoup.parse("<div id=title>Old</div >\n" +
"<p>1<p>2\n" +
"<table><tr><td>1</td></tr></table>");
doc.getElementById("title").text("New");
System.out.println(doc.toString());
I expect to get the following result:
<div id=title>New</span></div >
<p>1<p>2
<table><tr><td>1</td></tr></table>
Instead, I have:
<html>
<head></head>
<body>
<div id="title">New</div>
<p>1</p>
<p>2 </p>
<table>
<tbody>
<tr>
<td>1</td>
</tr>
</tbody>
</table>
</body>
</html>
Added by Jsoup:
- closing p tags
- double quotes for attribute values
- TBODY
- html, elements of the head and body
Can I convert modified HTML to original? Jericho does this, but he does not provide slick DOM manipulation methods, as Jsoup does.
source
share