blank
blank

Reputation: 18180

Is there a Java API for creating a XHTML document?

I want to provide a simple XHTML representation of each of the resources in a REST web service.

At the moment i'm using a StringBuilder to generate these which is both tedious and error prone. I don't see these changing after I publish the service but the process of coding each is a bit painful.

Is there a XHTML document writer api? Should I just use an XML writer? Which one? Should I just roll my own basic HTML document class - doctype is the same each time, i just need to set the title, metatags and body content, most of which (but not all content) is already in HTML for the GETs.

Or should I just use StringBuilder and stop whining? ;)

Thanks.

Upvotes: 2

Views: 2672

Answers (3)

user1050755
user1050755

Reputation: 11701

There seems to be a new solution (finally): https://j2html.com/

Upvotes: 3

Andy Gherna
Andy Gherna

Reputation: 2165

You could use something like jdom or dom4j. Either one provides a simple interface for building your document and then serializing it as an XML string. It's less brittle than using a StringBuilder.

UPDATE: Corrected dom4j link.

Upvotes: 2

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181460

I would give Apache's XMLBEANS a try. You can process XHTML's schema with it, and it will generate classes to handle (generate/validate) XHTML directly.

Hope it helps.

Upvotes: 1

Related Questions