Remove 'standalone="yes"' from generated XML
Solution 1:
in JAXB that is part of JDK1.6
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
Solution 2:
This property:
marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", false);
...can be used to have no:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
However, I wouldn't consider this best practice.
Solution 3:
You can either use
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
or
marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", false)
to disable the default XML declaration, and then add your custom XML declaration,
<?xml version="1.0" encoding="UTF-8"?>
by
marshaller.setProperty("com.sun.xml.bind.xmlHeaders",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
to the generated xml, thus avoiding the standalone="yes" property.
Solution 4:
just if someone else is still struggeling with this problem, you may consider using
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
to remove all of the XML declaration and just write your own String
at the beginning of your output stream / method