tags:

views:

81

answers:

3

Anyone have a sample of code using XmlRepresentation? I am currently using a StringRepresentation, but need it to return XML instead. It's for a RESTful web service.

import org.restlet.resource.XmlRepresentation;

+2  A: 

XmlRepresentation is an abstract class. Consider SaxRepresentation or DomRepresentation instead.

Jerome Louvel
+1  A: 

If you already have the XML document that you want to return working with your StringRepresentation, or have it in a String or can easily get it as a String, and you merely need to return the XML media type, you can do that with StringRepresentation:

new StringRepresentation("<Document>content</Document", MediaType.APPLICATION_XML);

or:

representation.setMediaType(MediaType.APPLICATION_XML);
Avi Flax
A: 

It seems you are using RESTlet. You might want to return the Class of your Representation itself and let RESTlet do the conversion to whatever format was requested (xml or json).

This is, if you are using RESTlet 2.0 see http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/285-restlet.html

chaos0815