Here you can find the source of marshall(Object obj, URL schemaURL, Class... classesToBeBound)
public static String marshall(Object obj, URL schemaURL, Class... classesToBeBound) throws JAXBException, SAXException
//package com.java2s; //License from project: Open Source License import org.xml.sax.SAXException; import javax.xml.XMLConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import java.io.StringWriter; import java.net.URL; public class Main { public static String marshall(Object obj, URL schemaURL, Class... classesToBeBound) throws JAXBException, SAXException { JAXBContext context = JAXBContext.newInstance(classesToBeBound); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); if (schemaURL != null) { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(schemaURL); marshaller.setSchema(schema); }/* ww w . j a v a2 s.c om*/ StringWriter writer = new StringWriter(); marshaller.marshal(obj, writer); return writer.toString(); } }