views:

95

answers:

2

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.

A: 

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.

Pablo Santa Cruz
+1  A: 

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.

Andy Gherna
The dom4j link tells me that "The internet is great." - although they provide a link to the sourceforge page they're not associated with dom4j you might want to update the link
Bedwyr Humphreys
The internet _IS_ great. Link is updated.
Andy Gherna
:) I'm trying out dom4j ... now I've more questions!
Bedwyr Humphreys