Pretty printing XML in Python

后端 未结 26 2286
一个人的身影
一个人的身影 2020-11-22 02:18

What is the best way (or are the various ways) to pretty print XML in Python?

26条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 03:04

    Take a look at the vkbeautify module.

    It is a python version of my very popular javascript/nodejs plugin with the same name. It can pretty-print/minify XML, JSON and CSS text. Input and output can be string/file in any combinations. It is very compact and doesn't have any dependency.

    Examples:

    import vkbeautify as vkb
    
    vkb.xml(text)                       
    vkb.xml(text, 'path/to/dest/file')  
    vkb.xml('path/to/src/file')        
    vkb.xml('path/to/src/file', 'path/to/dest/file') 
    

提交回复
热议问题