Good HTML object model in Java?

I am looking for an HTML object model in Java that is capable of parsing HTML (optional) and containing all HTML elements (and CSS) in an elegant object model.

I am looking for a clean java version of Groovy HTML Designer. (I’m out of luck with Google with this request.)

I want to be able to do things like:

HTML html = new HTML();
Body body = html.body();

Table table body.addTable(myCssStyle);
Row row = table.addRow("a", "b", "c").withCss(cssRowStyle);

etc.

+3
source share
3 answers

Jakarta ECS can do what you want.

+3
source

Check out Jsoup :

Example: (Creating 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:

+4
source

: xhtmlrenderer. http://code.google.com/p/flying-saucer//

This is not plain HTML (it's XHTML), but it can be a good starting point, right?

+1
source

Source: https://habr.com/ru/post/1729600/


All Articles