I'm splitting an incoming xml file using JAXB. I know this seems like a duplicate thread, However
Expected,
<?xml version="1.0"?>
Actual,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
I tried using JAXB_FRAGMENT which completely removes the first line
jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
And
jaxbMarshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
with and without Marshaller.JAXB_FRAGMENT
FYI, I'm using StringWriter
JAXBContext jaxbContext = JAXBContext.newInstance(ExportDocument.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);//
//jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
//jaxbMarshaller.setProperty("com.sun.xml.bind.xmlHeaders", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(employee, sw);
String xmlContent = sw.toString();
System.out.println(xmlContent);