1

In Axiom , I am not able to provide indenting option for OMElement.Using serialize method omelement is written into file. But it is not pretty print.

Is there any option available in Axiom parser? Code I used to write into a file.

 FileOutputStream fileOutputStream= new FileOutputStream("filename");
 XMLOutputFactory xmlOutputFactory= XMLOutputFactory.newInstance();
 XMLStreamWriterwriter = xmlOutputFactory.createXMLStreamWriter(fileOutputStream);
 omElement.serializeAndConsume(writer);
 writer.flush();
 writer.close();
V_Dev
  • 83
  • 6

1 Answers1

1

You can use a Transformer to add the indentation, as in the following code snippet:

Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(omElement.getSAXSource(true), new StreamResult(fileOutputStream));
Andreas Veithen
  • 8,868
  • 3
  • 25
  • 28
  • Problem with Transformer class is, It is not providing the option to preserving Entity element in the docType. – V_Dev Jul 16 '18 at 10:53