Skip to main content

How to marshal into javax.xml.transform.Source

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2008-03-19


I am using JAXWS and JAXB to build my web service application. I am struggling to get it work.

When unmarshaling from a file, javax.xml.transform.Source can be created from an input stream. It works fine.

But I have problem marshaling back to source. I can marshal it to System.out but want to reply to a client in form of javax.xml.transform.Source.

StringWriter writer = new StringWriter();

getMarshaller().marshal(o, writer);

Source source = new StreamSource(writer.toString());

Then I get: no protocol: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> . . . .

I have to return Source as I am implementing Provider

public class TestService implements Provider
public Source invoke(Source source)


Any idea?