Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top