Reputation: 34
JSoup seems to be adding extra br tags to my output as shown below. Is there a way to stop this from happening ?
JUnit Test :
@Test
public void testJsoup () throws MLException {
String htmlBody = "<body> <div> <br class='calibre1'></br> <br class='calibre1'></br></div> </body>";
Document doc = Jsoup.parse(htmlBody);
htmlBody = doc.select("body").first().toString();
System.out.println(htmlBody);
}
Console Output :
<body>
<div>
<br class="calibre1" />
<br />
<br class="calibre1" />
<br />
</div>
</body>
Regards, Danny
Upvotes: 1
Views: 1227
Reputation: 25340
I don't see any extra <br />
-Tags here ... do you mean line feed instead?
If yes, have a look here: jsoup line feed
What you can do is turning prettyPrint
off:
final String html = "<body> <div> <br class='calibre1'></br> <br class='calibre1'></br></div> </body>";
Document doc = Jsoup.parse(html);
// This line will keep your Html in one line
doc.outputSettings().prettyPrint(false);
System.out.println(doc.body());
Output:
<body> <div> <br class="calibre1" /><br /> <br class="calibre1" /><br /></div> </body>
Upvotes: 2