使用StAX格式化XML文件 [英] Formatting XML file using StAX

查看:151
本文介绍了使用StAX格式化XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用StAX XML流编写器来编写XML文件。它将所有数据写入一行。我希望所有标签都缩进而不是单行。

I am using StAX XML stream writer to write the XML file. It writes all the data in a single line. I want all the tags to be indented instead of a single line.

推荐答案

stax-utils 提供了类 IndentingXMLStreamWriter 来完成这项工作:

stax-utils provides class IndentingXMLStreamWriter which does the job:

XMLStreamWriter writer =
  XMLOutputFactory.newInstance().createXMLStreamWriter(...);
writer = new IndentingXMLStreamWriter(writer);
...

这篇关于使用StAX格式化XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆