If I do something like this with a jsoup Element
new Element("div").html("<p></p>")
The output of the toString()
method (or for that case the outerHtml()
) method yields something like this.
<div>
<p></p>
</div>
I cannot find anything in the documentation that says it adds newlines or spaces to whatever is added to Element
.
Is there any way to output it like that:
<div><p></p></div>
From what I can tell, pretty print settings are set on the Document
level.
You can get and set the setting, like so:
// Document doc = ...
doc.outputSettings().prettyPrint(); // true by default
doc.outputSettings().prettyPrint(false); // set to false to disable "pretty print"
Here is how one can cook up an empty Document
:
Document doc = new Document("");
// use Jsoup.parse("") if you don't mind the basic HTML stub:
// html, head, and body.
This is what I would do to print your Element
"as is" - without new lines:
Document doc = new Document("");
doc.outputSettings().prettyPrint(false);
doc.insertChildren(0, new Element("div").html("<p></p>"));
System.out.println(doc);
// prints: <div><p></p></div>
Document.OutputSettings#prettyPrint(boolean)
Document.OutputSettings#prettyPrint()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With