Marshaller m = JAXBContext.newInstance(new Class[] { Kml.class }).createMarshaller(); m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true ); m.setProperty( Marshaller.JAXB_FRAGMENT, false ); m.setProperty(javax.xml.bind.Marshaller.JAXB_ENCODING, "UTF-8"); final Kml kml = new Kml(); kml.createAndSetPlacemark() .withName("London, UK").withOpen(Boolean.TRUE) .createAndSetPoint().addToCoordinates(-0.126236, 51.500152); StringWriter sw = new StringWriter(); m.marshal(kml,sw); String s1 = sw.toString(); System.out.println(s1);