Skip to content Skip to sidebar Skip to footer

A Good Html Object Model In Java?

I'm looking for an HTML object model in Java, capable of parsing HTML (not required) and containing all HTML elements (and CSS as well) in an elegant object model. I'm looking for

Solution 1:

Check out Jsoup:

Example:(Building some html)

Documentdoc= Document.createShell("");

Elementheadline= doc.body().appendElement("h1").text("thats a headline");
ElementpTag= doc.body().appendElement("p").text("some text ...");
Elementspan= 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:

Solution 2:

Solution 3:

Just an idea: you could take a look at the source code of xhtmlrenderer project. http://code.google.com/p/flying-saucer//

It's not plain HTML (it's XHTML), but may be a good starting point, don't you think?

Post a Comment for "A Good Html Object Model In Java?"