I was confused by an old Microsoft API which simply had a write method, that saved the XML to file.
Here's the right way:
OutputFormat fmt = new OutputFormat();
StringWriter sw = new StringWriter ();
XMLSerializer serial = new XMLSerializer(sw, fmt);
serial.serialize(
doc);
System.out.println(stringOut.toString());