I'm using JAXB in order to generate XML files, and due to a business need I'm currently writing it to the middle of some other XML file using XMLEventWriter:
marshaller.marshal(jaxbElement, xmlEventWriter);
And currently setting some properties like:
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8");
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
But, besides having the JAXB_FORMATTED_OUTPUT set to true, my XML is not being formatted.
Does anyone knows what may be the problem? This only happens when I use the XMLEventWriter...
Thanks in advance.
When you are using an
XMLEventWriter
as a sink, the JAXB marshaller is only in charge of sending the appropriate XML events to it and theXMLEventWriter
may still choose to write out unformatted XML. My advice is to check the configuration of yourXMLEventWriter
in addition toMarshaller
.