I am using Spring XML and Castor for converting xml to object and object to xml. On marshalling, the content written to the xml is a plain xml string. Is there a way to write to the xml in a formatted manner ?
Hi by default Castor XML uses xerces for xml parsing, you need to instantiate OutputFormat object passing it your document object, encoding and indenting=true, please keep in mind if you enable the indenting it will make your processing slow.
OutputFormat format = new OutputFormat(document);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.