Html5 alternative to Jakarta ECS (or similar tools)?

I was wondering if there are any good html5 generation tools for Java, similar to the Jakarta ECS project , which has long since retired. I see there are questions about programming html generation via java, but most of the answers refer to legacy tools that do not fully support html5.

I'm looking at this question in particular: Good HTML Object Model in Java?

+3


source to share


1 answer


Yes, there is one: Jsoup .

jsoup implements the WHATWG HTML5 specification and parses HTML into the same DOM as modern browsers.

  • strip and parse HTML from url, file or string
  • find and retrieve data using DOM traversal or CSS selector
  • manage HTML elements, attributes and text
  • clear content submitted by users to a safe whitelist to prevent XSS attacks
  • output tidy HTML

Example: (Generating some html)

Document doc = Document.createShell("");

Element headline = doc.body().appendElement("h1").text("thats a headline");
Element pTag = doc.body().appendElement("p").text("some text ...");
Element span = pTag.prependElement("span").text("That's");

System.out.println(doc);

      



Output:

<html>
 <head></head>
 <body>
  <h1>thats a headline</h1>
  <p><span>That's</span>some text ...</p>
 </body>
</html>

      

Documentation:

+10


source







All Articles