How to pretty print XML from Java?

后端 未结 30 2930
慢半拍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:53

    there is a very nice command line xml utility called xmlstarlet(http://xmlstar.sourceforge.net/) that can do a lot of things which a lot of people use.

    Your could execute this program programatically using Runtime.exec and then readin the formatted output file. It has more options and better error reporting than a few lines of Java code can provide.

    download xmlstarlet : http://sourceforge.net/project/showfiles.php?group_id=66612&package_id=64589

提交回复
热议问题