views:

3070

answers:

3

Hi people,

Do you know of a JAXB setting to prevent standalone="yes" from being generated in the resulting XML?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+4  A: 

marshaller.setProperty("com.sun.xml.bind.xmlDeclaration", Boolean.FALSE);

can be used to have no "<?xml version="1.0" encoding="UTF-8" standalone="yes"?>"

However i wouldnt consider this best practice.

Sam
Thanks, this is exactly what I needed. I would agree it is best practice to include the line, but a web service I am interfacing with does not expect it.
jgrowl
+1  A: 

If you make document dependent on DOCTYPE (e.g. use named entities) then it will stop being standalone, thus standalone="yes" won't be allowed in XML declaration.

However standalone XML can be used anywhere (while non-standalone is problematic for XML parsers that don't load externals).

I don't see how this declaration could be a problem, other than for interoperability with software that doesn't support XML, but some broken homegrown XML-like voodoo.

porneL