Formatting XML file using StAX

后端 未结 3 489
闹比i
闹比i 2020-12-10 08:51

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.

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 09:19

    stax-utils provides class IndentingXMLStreamWriter which does the job:

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

提交回复
热议问题