1JAXBContext context = JAXBContext.newInstance(Something.class);
2Marshaller marshaller = context.createMarshaller();
3marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
4StringWriter out = new StringWriter();
5marshaller.marshal(something, out);
6String xml = out.toString();
7