简体   繁体   English

使用Castor在Spring xml中处理列表

[英]Handling List in Spring xml using Castor

I am using Spring XML and Castor for converting xml to object and object to xml. 我正在使用Spring XML和Castor将xml转换为对象并将对象转换为xml。 On marshalling, the content written to the xml is a plain xml string. 编组时,写入xml的内容是纯xml字符串。 Is there a way to write to the xml in a formatted manner ? 有没有一种以格式化的方式写入xml的方法?

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对象,将其传递给您的文档对象,encoding和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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM