3

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.

plemos
  • 31
  • 1
  • 2
  • Strange... It usually works. Is there a chance that you are creating Unix EOL symbols and then viewing the file using Notepad on windows? – AlexR Oct 12 '12 at 16:18
  • Posting a minimal example that reproduces the problem would go a long way. – Marko Topolnik Oct 12 '12 at 16:21

2 Answers2

3

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 the XMLEventWriter may still choose to write out unformatted XML. My advice is to check the configuration of your XMLEventWriter in addition to Marshaller.

Marko Topolnik
  • 179,046
  • 25
  • 276
  • 399
0

Unfortunately, the default XmlEventWriter implementation does not indent. The stax-utils library provides a IndentingXMLEventWriter which might help in these cases.

rec
  • 8,872
  • 3
  • 24
  • 41