How to pretty print XML from Java?

后端 未结 30 2516
慢半拍i
慢半拍i 2020-11-22 01:55

I have a Java String that contains XML, with no line feeds or indentations. I would like to turn it into a String with nicely formatted XML. How do I do this?



        
30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 02:44

    Hmmm... faced something like this and it is a known bug ... just add this OutputProperty ..

    transformer.setOutputProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, "8");
    

    Hope this helps ...

提交回复
热议问题