如何在java中生成一个大的(30MB+)xml文件?
文件本身不是那么大,应该适合内存。但一旦将其与其他开销因素结合起来,问题就开始出现。我们正在内存中构建 DOM,这对我们来说是无法扩展的。使用原始输出流似乎有问题,因为我们必须小心转义字符。
有哪些好的方法可以做到这一点?
有这方面的商品库吗?
The file itself is not that big, should fit in memory. But once you combine that with other overhead factors then starts to become a problem. We are building a DOM in memory and that is not scaling for us. Using raw output streams seems problematic in the sense that we have to be careful about escaping characters.
What are some good approaches for doing this?
Are there any goods libs for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
STAX 提供了一个方便的 API,用于将 XML 写入输出流。简单教程此处。
STAX provides a convenient API with which to write XML to output stream. Easy tutorial here.
尝试 XStream
功能
Try XStream
Features
通过 Saxon,您可以将 StAX XMLStreamWriter API 与序列化器结合使用,序列化器使您可以完全控制 xsl:output 中定义的序列化属性,例如控制缩进、CDATA 部分的使用等的能力。请参阅 s9api 序列化器班级。
With Saxon, you can use the StAX XMLStreamWriter API in conjunction with a Serializer that gives you full control of the serialization properties as defined in xsl:output, for example the ability to control indentation, use of CDATA sections, etc. See the s9api Serializer class.
这取决于您的数据的结构,但 StAX 实现可能就是您正在寻找的 - 例如 Woodstock。
It depends on how your data is structured, but a StAX implementation might be what you are looking for - like Woodstock for example.