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 ?
我使用Spring XML和Castor将xml转换为object,将对象转换为xml。在编组时,写入xml的内容是一个普通的xml字符串。有没有办法以格式化的方式写入xml?
1 个解决方案
#1
0
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.
嗨默认情况下,Castor XML使用xerces进行xml解析,你需要实例化OutputFormat对象,传递你的文档对象,编码和indenting = true,请记住,如果启用缩进,它将使你的处理变慢。
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);
#1
0
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.
嗨默认情况下,Castor XML使用xerces进行xml解析,你需要实例化OutputFormat对象,传递你的文档对象,编码和indenting = true,请记住,如果启用缩进,它将使你的处理变慢。
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);