2

for those who tried the JAXB library, is there a way to create the file properly formatted? The output is a 1 line file, and it gives me big problems. >,<

//xml creation
    JAXBContext ctx = null;
    try {
        ctx= JAXBContext.newInstance("Pojo");
        Marshaller marshaller = ctx.createMarshaller();
        marshaller.marshal(train, new File(xml_output_file_path));
    } 
    catch (Exception e) {
        e.printStackTrace();
    }
Robdll
  • 5,865
  • 7
  • 31
  • 51

2 Answers2

4

You can use the following to enable pretty-print:

marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Simon
  • 6,293
  • 2
  • 28
  • 34
0

Before marshalling, add:

marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

To add UTF-8 encoding, set property to marshaller:

marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228